Duncan,
I assume you're referring to a 3rd-party solution -- one which I'd like to
hear some more about. That sounds like a potentially good solution in a
real-world, work environment.
Unfortunately, I'm one of the huge ranks of unemployed senior developers,
so I'm converting this app only as a learning exercise. Learning how to do
Win32 API calls from C# is probably more useful in my situation.
As long as we're on that subject, don't hesitate to e-mail if anyone is
even thinking of hiring a senior VB/ASP/COM+/.NET developer in the
Philadelphia - Wilmington, DE region. I'm your man!
Bill
On Sun, 19 May 2002 01:56:17 +0100, Duncan Godwin
<[EMAIL PROTECTED]> wrote:
>Wouldn't it be better if you are porting the app to C# to make use of the
>Frameworks Registry functions which are far more maintainable and easier to
>get working.
>
>----- Original Message -----
>From: "Bill Schmidt" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Saturday, May 18, 2002 6:19 PM
>Subject: [DOTNET] Win32 API syntax problem, using C#
>
>
>> I'm trying to convert a working VB.NET WinForms application to C#, and
I'm
>> having trouble with the string buffer being returned from a Win32 API
>call.
>>
>> First, my working VB.NET code:
>> Public Declare Function GetPrivateProfileString Lib "kernel32" _
>> Alias "GetPrivateProfileStringA" _
>> (ByVal lpApplicationName As String, _
>> ByVal lpKeyName As String, ByVal lpDefault As String, _
>> ByVal lpReturnedString As String, ByVal nSize As Integer, _
>> ByVal lpFileName As String) As Integer
>>
>> lngSize = 127
>> strDBLocation = Space(lngSize) & Chr(0)
>> lngDummy = GetPrivateProfileString("DBLocation", "Path", _
>> vbNullString, strDBLocation, lngSize, strINIPath)
>> strDBLocation = Left(strDBLocation, InStr(strDBLocation, Chr(0)) - 1)
>>
>> This code returns the correct strDBLocation string. It also sets
lngDummy
>> to the length of the returned string (23).
>>
>> Now, what I think is the equivalent C# code:
>> [DllImport("kernel32.dll", EntryPoint="GetPrivateProfileStringA",
>> CharSet=CharSet.Ansi)]
>> public static extern int GetPrivateProfileString(
>> string lpApplicationName, string lpKeyName, string lpDefault,
>> string lpReturnedString, int nSize, string lpFileName);
>>
>> intSize = 127;
>> strDBLocation = new string(' ', intSize) + (char) 0;
>> intDummy = GetPrivateProfileString("DBLocation", "Path", null,
>> strDBLocation, intSize, strINIPath);
>> i = strDBLocation.IndexOf((char) 0);
>> if (i >= 0)
>> strDBLocation = strDBLocation.Substring(0, i);
>>
>> When I run this in the identical environment, intDummy gets set to 23
>> (which is correct), but strDBLocation remains the same as before the call
>> to GetPrivateProfileString (a 127-char string filled with spaces). I
>> verified that strINIPath is set to the same value as in the VB app.
>>
>> Can someone please tell me what I'm doing wrong? (I've tried switching
to
>> CharSet.Auto and CharSet.Unicode, with no success.)
>>
>> Bill
>>
>> You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
>> subscribe to other DevelopMentor lists at http://discuss.develop.com.
>
>You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
>subscribe to other DevelopMentor lists at http://discuss.develop.com.
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.