Seems I can't call a Win32 DLL exported function from a VB6 function. I can
call it successfully from a VB6 Form_Load event. Strange. Any ideas? Here's
the exported C++.NET function and VB6 Function.
// Win32DLL.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "Win32DLL.h"
BOOL APIENTRY DllMain(
HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
// This is an example of an exported variable
// WIN32DLL_API int nWin32DLL = 0;
// This is an example of an exported function.
// WIN32DLL_API int fnWin32DLL(int varIn)
extern "C" __declspec(dllexport) int fnWin32DLL(int varIn)
{
int varOut;
varOut = varIn;
return 42 * varIn;
}
// This is the constructor of a class that has been exported. See Win32DLL.h
for the class definition
CWin32DLL::CWin32DLL()
{
return;
}
Private Sub cmdCompute_Click()
Dim x As Long
x = DoExternFunc(CInt(txtInputVarA.Text))
'x = fnWin32DLL(CInt(txtInputVarA.Text))
txtInputVarA.Text = CStr(x)
End Sub
'Set up global declarations and declare functions
Declare Function fnWin32DLL Lib
"C:\jhoggood\Applications\CommonC\BuildFiles\Win32DLL\Debug\Win32DLL.dll"
(ByVal varIn As Long) As Long
Public Function DoExternFunc(ByVal myInputVarA As Long) As Long
DoExternFunc = fnWin32DLL(myInputVarA)
'DoExternFunc = myInputVarA * 5
End Function
Michael Fitzpatrick - 12 Dec 2003 05:43 GMT
You probably need to declare the function as __stdcall. Usually the default
for C++ is to use __cdecl
This is how the stack frame is managed.
> Seems I can't call a Win32 DLL exported function from a VB6 function. I can
> call it successfully from a VB6 Form_Load event. Strange. Any ideas? Here's
[quoted text clipped - 86 lines]
> 'DoExternFunc = myInputVarA * 5
> End Function