• Advertisement

Archived

This topic is now archived and is closed to further replies.

Init window from dll???

This topic is 5272 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone, I need some help creating a window, because I alway get errors. I want to call the InitWindow()-function from my exe-file. The function should be located in an dll. So here the code I got: the dll-code: #include <Windows.h> #include <StdIO.h> extern "C" { BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID pReserved) { __declspec(dllexport) void InitWindow() { //Create the window } }; the exe-file-code: #include <windows.h> BOOL (__stdcall* InitWindow)(); HMODULE hDLL; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { hDLL = LoadLibrary("engine32.dll"); InitWindow = (BOOL (__stdcall*)())(GetProcAddress(hDLL, "InitWindow")); if(InitWindow == NULL) { MessageBox(NULL, "Error!!!", "Error", MB_OK); } InitWindow(); FreeLibrary(hDLL); return 0; } I already know how to create a window, but I don''t get the code converted into an dll. Please help me! thx!!!!

Share this post


Link to post
Share on other sites
Advertisement
Don''t use __declspec(dllexport), use a .def file instead. __declspec(dllexport) does not export functions with the names most people expect.

If you look at the exports in the dll, you''ll probably see that it was exported as "_InitWindow@0" or something similiar. If you use a .def file it will be exported as plain "InitWindow".

Share this post


Link to post
Share on other sites
Don''t you also need to return a value from the dll entry point to indicate success of loading? It could be that your dll handle is invalid!

James

Share this post


Link to post
Share on other sites
Hey stefan ... i know this probably seems really nit-picky but your headers look really odd with the capital letters in them, you know that headers are not generally case sensitive right?


An ASCII tetris clone... | AsciiRis

Share this post


Link to post
Share on other sites
@ Anon Mike: Well, I read that when I write --extern "C"-- the function names get not exported as "_InitWindow@0" or something similiar.

@ jamessharpe: I already have some other functions (file reading) working correctly. So I don''t think the dll handle is invalid.


Well, I just wanted to know, what part of code had to be in the dll and what part in the exe-file?!

Share this post


Link to post
Share on other sites

  • Advertisement