I have a piece of code giving me fits. I am attempting to call a DLL function, which should return a String to the calling environment.
Here is the DLL source code:
Here is the Module Declaration Statement:
The Form contains a Text Control and a Button Control. Here is the code associated with the Button control:
When I compile the DLL and copy it to the proper location, I then Start the Visual Basic program. When I press the Button I get the error:
The instruction at "0x779d926" referenced memory at "0x57202c6b". The memory could not be "read"
If I pass the Visual Basic String variable ByRef then I get the error:
The instruction at "0x779d926" referenced memory at "0x57202c6b". The memory could not be "written"
Can anyone tell me what the problem really is and the solution?
Thanks in advance
Brad
Here is the DLL source code:
Code:
// MYDLL.DLL
#include <windows.h>
BOOL WINAPI DllMain( HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved )
{
}
void MyDllFunction( char myString[20] )
{
wsprintf( myString, "%s", "Hello, World" );
//MessageBox( NULL, myString, "MyDllFunction Caption", MB_OK );
}
Here is the Module Declaration Statement:
Code:
Declare Sub MyDllFunction Lib "D:\VisualBasicAPI\MYDLL.DLL" (ByRef lpString As String)
The Form contains a Text Control and a Button Control. Here is the code associated with the Button control:
Code:
Private Sub Command1_Click()
Dim TextMessage As String
MyDllFunction (TextMessage)
Text1.Text = TextMessage
End Sub
When I compile the DLL and copy it to the proper location, I then Start the Visual Basic program. When I press the Button I get the error:
The instruction at "0x779d926" referenced memory at "0x57202c6b". The memory could not be "read"
If I pass the Visual Basic String variable ByRef then I get the error:
The instruction at "0x779d926" referenced memory at "0x57202c6b". The memory could not be "written"
Can anyone tell me what the problem really is and the solution?
Thanks in advance
Brad