Necuima Posted November 15, 2014 Share Posted November 15, 2014 Hi, I hope that this is not 'too simple' for anyone replying, but I'm a C novice so your advice will be most appreciated. The background is that I'm trying to learn about DLLs and using them in a Windows 7 environment. I have created a simple 'HelloWorld-ish' DLL in C which compiles OK. It is meant to receive a string passed to it from a calling C++ program and display that string in a messagebox. I am aware that strings are handled differently in C and C++. I suspect that my 'caller' program is passing the string OK but that my C DLL is not handling it OK. The DLL displays just the first character of the passed string. Here's the code from the DLL - first the dll.h: #ifndef _DLL_H_ #define _DLL_H_ #if BUILDING_DLL # define DLLIMPORT __declspec (dllexport) #else /* Not BUILDING_DLL */ # define DLLIMPORT __declspec (dllimport) #endif /* Not BUILDING_DLL */ DLLIMPORT void HelloWorld (char *str_in); #endif /* _DLL_H_ */ And the HelloWorld.c code: #include "E:/documents/C_PlusPlus/HelloWorld_C/dll.h" #include <windows.h> #include <stdio.h> #include <stdlib.h> DLLIMPORT void HelloWorld (char *str_in) { MessageBox (0, str_in, "Try 2", MB_ICONINFORMATION); } BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ , DWORD reason /* Reason this function is being called. */ , LPVOID reserved /* Not used. */ ) { switch (reason) { case DLL_PROCESS_ATTACH: break; case DLL_PROCESS_DETACH: break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; } /* Returns TRUE on success, FALSE on failure */ return TRUE; } My environment in this context is Windows 7 64 bit and Dev-C++ I have scoured the Internet and forums but I can't seem to find what I'm looking for. Any advice will be most appreciated and thank you in anticipation. Cheers Link to comment Share on other sites More sharing options...
Necuima Posted November 17, 2014 Author Share Posted November 17, 2014 Hi, after much Googling and trial and error I managed to create the dll in C++ (rather than my first attempt above in C). The C++ dll works! Thanks to anyone who had a look at this. Cheers from Oz. Link to comment Share on other sites More sharing options...
Recommended Posts