Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

API Functions in VB2005 .NET...

SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
[b][red]This message was edited by Sephiroth at 2007-2-20 17:54:52[/red][/b][hr]
I am writing a lengthy emulation program to run DOS games under XP adn while the application works, I cannot store data the way I wish to, in an INI file. In C/C++ I'd simply use the "GetPrivateProfile***" functions, and you're supposed to be able to use them in VB, but they're not working. They spew errors at run-time no matter what I do. I found some info on using them in VB5 and 6, but this is .NET and may be my problem. Below is how I declare the functions I need.
[code]
Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal sSectionName As String, ByVal sKeyName As String, _
ByVal lDefault As Long, ByVal sFileName As String) As Long
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal sSectionName As String, ByVal sKeyName As String, _
ByVal sDefault As String, ByVal sReturnedString As String, ByVal lSize As Long, ByVal sFileName As String) As Long
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal sSectionName As String, ByVal sKeyName As String, _
ByVal sString As String, ByVal sFileName As String) As Long
[/code]
These compile and all, but whenever they're called they fail. Can somebody tell me how the heck to write to a simple INI file in VB .NET?

*EDIT*

The exact error is as follows:
[code]
Additional Information: A call to PInvoke function '486 Launcher!_486_Launcher.winPrimary::GetPrivateProfileInt' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
[/code]

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]


Comments

  • melissa_may1melissa_may1 Member Posts: 937
    Hey there!

    Why not just use the file functions to write the data out? Wouldn't that be the easiest way?

    If you really want the INI file to work, take a look at the techniques shown here:

    http://www.codeguru.com/forum/archive/index.php/t-189920.html

    Good Luck!

    : [b][red]This message was edited by Sephiroth at 2007-2-20 17:54:52[/red][/b][hr]
    : I am writing a lengthy emulation program to run DOS games under XP adn while the application works, I cannot store data the way I wish to, in an INI file. In C/C++ I'd simply use the "GetPrivateProfile***" functions, and you're supposed to be able to use them in VB, but they're not working. They spew errors at run-time no matter what I do. I found some info on using them in VB5 and 6, but this is .NET and may be my problem. Below is how I declare the functions I need.
    : [code]
    : Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal sSectionName As String, ByVal sKeyName As String, _
    : ByVal lDefault As Long, ByVal sFileName As String) As Long
    : Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal sSectionName As String, ByVal sKeyName As String, _
    : ByVal sDefault As String, ByVal sReturnedString As String, ByVal lSize As Long, ByVal sFileName As String) As Long
    : Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal sSectionName As String, ByVal sKeyName As String, _
    : ByVal sString As String, ByVal sFileName As String) As Long
    : [/code]
    : These compile and all, but whenever they're called they fail. Can somebody tell me how the heck to write to a simple INI file in VB .NET?
    :
    : *EDIT*
    :
    : The exact error is as follows:
    : [code]
    : Additional Information: A call to PInvoke function '486 Launcher!_486_Launcher.winPrimary::GetPrivateProfileInt' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
    : [/code]
    :
    : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
    :
    :
    :



    [purple]Melissa[/purple]

Sign In or Register to comment.