Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Moving a C++ Exe to a DLL

I am new to C++. I normally program in VB.NET, but I have a program that has a control on it that has a memory leak and I am trying to eliminate it or reduce it by creating this control dynamically on a form. I have tried it with vb6 and VB.net but it will not recognize it and allow me to do this dynamically.

I have generated a C++ program with this same control to test a theory of creating and destroying this object. Now I have to turn this exe into a DLL and call it from a VB6 app. I am now sort of lost as to how to take it from a standalone EXE to a DLL. One twist to this program, is that the VB6 app has to pass some information to this DLL and it is to return a boolean from the DLL.

What do I need to do to make this happen. If need be I can attach a sample of my program.

Thanks Jim
[823 byte] By [Jimboden] at [2007-11-11 10:18:22]
# 1 Re: Moving a C++ Exe to a DLL
Normally u don't need more than changing the project type from "exe" project to "win library" projetc, and here u need to change the main() function to DllMain() for example.
U may make function like this (to return bool and pass char for example ):
__declspec(dllexport) WINAPI bool prog(char entry);

and your main should look like :

BOOL WINAPI DllMain(HINSTANCE hInstA, DWORD dwReason, LPVOID lpvReserved)
{
switch (dwReason) {
case DLL_PROCESS_ATTACH: hInst = hInstA; break;
case DLL_PROCESS_DETACH: hInst = 0; break;}
return TRUE;
}
Amahdy at 2007-11-11 20:59:03 >
# 2 Re: Moving a C++ Exe to a DLL
Amahdy, That is what I thought. But I am using MS Studio 2003 and selecting a C++ project out of that, and I have yet find a void main or a bool winapi dllmain in any of the programs.

Jim
Jimboden at 2007-11-11 21:00:04 >
# 3 Re: Moving a C++ Exe to a DLL
u should creat it ; make it yourself :
BOOL WINAPI DllMain()
copy it as it is and don't make any changes in it it's for initializing the dll and make it run propably with vb application and catch normal knowen erros ..

__declspec(dllexport) WINAPI
this function as explain is a form for exportable function to vb application too , make your function here .. and declare it same as the way u declare an API under vb ..
for example if the dll application name is test.dll and u made like my function "prog()", in vb it will be :
private declare function prog lib "test.dll" (byval entry as byte) as boolean
and of course your test.dll must be registred or in the same vb application path .
Amahdy at 2007-11-11 21:01:13 >