Hi,

Im getting an error if i try to read the file with 'GetVar' when I click on opentoolstripmenu item.

How to I fix this?

this is my error:
Code:
A call to PInvoke function 'Map Editor!Map_Editor.SaveMap::GetPrivateProfileString' 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.
this is the code:
Code:
    Private Sub OpenToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles OpenToolStripMenuItem.Click

        'LoadMap(InputBox("Please enter the path you want to open.", "Load Map", "\Maps\map1.map"))

        Call PutVar("Test.ini", "TEST", "what", "hell5o")

        MsgBox(GetVar(Windows.Forms.Application.StartupPath & "/test.ini", "TEST", "what"))

    End Sub
this is the sub:
Code:
    

 ' Text API
    Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyname As String, ByVal lpString As String, ByVal lpfilename As String) As Long
    Private 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 Long, ByVal lpfilename As String) As Long

Public Function GetVar(File As String, Header As String, Var As String) As String
        Dim sSpaces As String   ' Max string length
        Dim szReturn As String  ' Return default value if not found
        szReturn = vbNullString
        sSpaces = Space$(5000)
        Call GetPrivateProfileString((Header), Var, szReturn, sSpaces, Len(sSpaces), File)
        GetVar = RTrim$(sSpaces)
        GetVar = Left$(GetVar, Len(GetVar) - 1)
    End Function

    ' writes a variable to a text file
    Public Sub PutVar(File As String, Header As String, Var As String, Value As String)
        Call WritePrivateProfileString((Header), Var, Value, Windows.Forms.Application.StartupPath & "/" & File)
    End Sub