This is a follow-up question to this question because I'm losing my mind over this right now.
Someone pointed me to this article and I'm trying to copy section 4 from there.
So I created an empty C++ Project in MSVC++2010, created a new .cpp file inside it, and put the following code in there:
#include <windows.h>
#define CCONV _declspec(dllexport) // used to be __stdcall but resulting DLL is identical
int CALLBACK LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize,
LPSTR lpszCmdLine)
{
return 1;
}
short CCONV PassInteger (short intgr, short far *pintgr)
{
*pintgr = intgr;
return intgr + 1;
}
(I got the LibMain
code from here but I think it doesn't do anything here.)
Then, I added a .def file to the project and put this in it:
;vb6dll32 DEF File
LIBRARY vb6dll32
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE
EXPORTS
PassInteger
The compiler outputs two warnings that CODE
and DATA
in the .def file are not supported for the current target, but it eventually compiles and generates the file vb6dll32.dll
which I have then copied to C:\windows\system
and ...\system32
and C:\
.
Then I have created a VB6 project, put a button into the form and added this sourcecode:
Private Declare Function PassInteger Lib "vb6dll32.dll" _
(ByVal intgr As Integer, pintgr As Integer) As Integer
Private Function BuiltIntest() As Integer
Dim i As Integer
Dim ir As Integer
i = 7
i = PassInteger(i, ir)
Print i, ir
Return
End Function
Private Sub Command1_Click()
MsgBox (BuiltIntest())
End Sub
Now, when I click the button, it still gives me "Runtime error '53': file vb6dll32.dll not found." (This happens even if I give it a fully specified path in the VB source code, e.g. "C:\vb6dll32.dll" and the file is definitely there. I tried giving its location without path and without ".dll" and so on, nothing changes.)
What also bugs me is, when I run regsvr32 c:\vb6dll32.dll
it also tells me "The module C:\vb6dll32.dll could not be loaded. etc etc" .. I have no idea what it should do but that should generally do something for DLL files, right?
What am I doing wrong?! Thanks for your help.
Maybe your vb6dll32.dll is dynamically linked and depends on stuff like MSVCR100.dll, which isn't easy to locate. Check imports and put these dlls beside your vb6dll32.dll, or link it statically (/MT /LD).
Also you really don't need these CODE and DATA lines in the .def file.