All,
I have searched the archives here as well as other resources and I am still having an issue with calling a function in a C++ dll from VB. I have pasted the VB test code that I am using and the C++ function declare below in hopes that some one can spot something that I am doing wrong.
When running the test code the dll loads successfully but a call to the TestScript() function raises the error "Can't find DLL entry point test_vbscript in C:\Mcam91\Chooks\vbscript.dll" I have tried a number of things including declaring the TestScript function to return an integer or a long and in both cases makes not apparent difference. We have also tried with and without declaring __declspec in the C++ declaration.
I am running XP Pro, VB6, VC6++
Code:
' -- Module Declares
Public Declare Function TestScript Lib "C:\Mcam91\Chooks\vbscript.dll" Alias "test_vbscript" () As Integer
Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Public Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Public Const DEF_SCRIPT_DLL As String = "C:\Mcam91\Chooks\vbscript.dll"
Public Sub Main()
On Error GoTo PROC_ERR
Dim lngRet As Long
Dim ret As Integer
' -- Works as expected
lngRet = LoadLibrary(DEF_SCRIPT_DLL)
If lngRet <> 0 Then
' -- Should call a simple messagebox
Call TestScript '<- Raises error
' -- Check
If ret = 0 Then
MsgBox "Call to TestScript failed ", vbExclamation, "DLL Test"
Else
' Add code...
End If
Else
MsgBox "Could not load dll '" & DEF_SCRIPT_DLL & "' ", vbExclamation, "DLL Test"
End If
PROC_EXIT:
' -- Clean up
If lngRet <> 0 Then FreeLibrary lngRet
Exit Sub
PROC_ERR:
Err.Source = "modCode::Main(Sub)"
MsgBox Err.Description & vbCrLf & vbCrLf & _
"Error Number " & Err.Number & vbCrLf & _
"Error Source " & Err.Source & " ", vbExclamation, "DLL Test"
Debug.Print Err.Description
Resume PROC_EXIT
End Sub
/////// C++ Code Begins /////////
/* __________ test_vbscript __________ */
__declspec(dllexport) int __stdcall test_vbscript(void)
{
int iRet = MessageBox (NULL, "Success", "VBScript test", MB_OK);
CString str("AfxMessageBox text");
iRet = AfxMessageBox(str, MB_SETFOREGROUND);
return(99); // for testing
}
/////// C++ Code Ends /////////