|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++.windows.32-bits - Create DLL callable from VB/VBA?
I'm trying to create a DLL which I can call from VB/VBA (Office 97). The DLL
appears to have a valid entry point and the calling conventions seem correct but
VBA gives me an error 48 - "DLL not found" which sometimes means the DLL is not
properly constructed even though it is there.
my command line is:
dmc test.c -WD -S -L/Entry:DllEntry
test.c is:
long __stdcall DllEntry(void *i,void *j,void *k){
return 1;
}
long __export __stdcall isub2(long *i,long *j){
return *i-*j;
}
test.def is:
LIBRARY "test.dll"
EXETYPE NT
SUBSYSTEM WINDOWS
EXPORTS isub2=_isub2 8
I have been able to create DLLs which work using Masm32 and various other C
compilers but so far I am missing something needed to get this to work with
Digital Mars.
Apr 18 2005
I need a DLL that I can call from VB, so I would be interested if anyone comes
up with a fix for your problem. The only DLL example I have found uses __cdecl,
which VB doesn't like unless you use some macros. Example code:
// dmcdll.c
#include <windows.h>
#include "dmcdll.h"
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID
lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH: // Colon not semi-Colon
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
{
__declspec( dllexport) int DoSomething( int a, int b)
{
return a*b*2;
}
}
-> Build DLL command: dmc -mn -WD dmcdll.c kernel32.lib
// dmcdll.h
// If I am not mistaken, it is not necessary to include the variable
// names here, only the types, but this is the way the sample was done.
__declspec( dllexport ) BOOL APIENTRY DllMain(HANDLE hModule, DWORD
ul_reason_for_call, LPVOID lpReserved)
__declspec( dllexport ) int DoSomething( int a, int b);
-> Build lib with: implib /noi /system dmcdll.lib dmcdll.dll
// dmctest.dll
#include <stdio.h>
#include <windows.h>
#include "dmcdll.h"
int main()
{
printf("Result: %d\n", DoSomething( 12, 32);
}
-> Build exe with dmc dmctest.c dmcdll.lib
TestDLL.exe works as advertised but VB returns an Error 49 "Bad DLL calling
convention."
What's the rest of the story for using __stdcall?
Mar 17 2006
|