www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.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++ - dll supportt

↑ ↓ ← qqqqxxx <qqqqxxx_member pathlink.com> writes:
how do i create a dll using dmc compiler
Feb 10 2006
↑ ↓ → Bertel Brander <bertel post4.tele.dk> writes:
qqqqxxx wrote:
 how do i create a dll using dmc compiler
 

A quick example: First the source of the .dll, put it into 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: 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; } Then a headerfile called dmcdll.h: __declspec( dllexport ) BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved); __declspec( dllexport ) int DoSomething(int a, int b); And a small test program called dmctest.c: #include <stdio.h> #include <windows.h> #include "dmcdll.h" int main() { printf("Result: %d\n", DoSomething(12, 32)); return 0; } Now we can build the dll with this command: dmc -mn -WD dmcdll.c kernel32.lib The we create a .lib from the .dll: implib.exe /noi /system dmcdll.lib dmcdll.dll And compile our test program, using the .lib: dmc dmctest.c dmcdll.lib Then you can run dmctest.exe, which with a bit of lock should print: Result: 768 -- Absolutely not the best homepage on the net: http://home20.inet.tele.dk/midgaard But it's mine - Bertel
Feb 10 2006