Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » [Help] How to build DLL using g++ in CDT ?
[Help] How to build DLL using g++ in CDT ? [message #181384] Fri, 22 December 2006 21:42
Eclipse UserFriend
Originally posted by: syan.tbdnetworks.com

Hi,

I tried creating a DLL and a tester program in CDT but not very successful.

MyDll project:

// MyDll.cpp : Defines the entry point for the DLL application.
//
#include <iostream>
#include <string>
#include "stdafx.h"

using namespace std;

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
cout << "DllMain called" << endl;
return TRUE;
}

int _stdcall sum(int x , int y)
{
cout << "SUM called" << endl;
return x+y;
}

MyDll.def:

LIBRARY MyDll

EXPORTS

sum @1

MyDll.dll is built in debug as:

**** Build of configuration Debug for project MyDll ****

make -k all
Building file: ../MyDll.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"MyDll.d"
-MT"MyDll.d" -o"MyDll.o" "../MyDll.cpp"
Finished building: ../MyDll.cpp

Building target: MyDll.dll
Invoking: GCC C++ Linker
g++ -shared -o"MyDll.dll" ./MyDll.o
Finished building target: MyDll.dll

Build complete for project MyDll


My tester has the following code:

// Get a handle to the DLL module.
hinstLib = LoadLibrary("MyDll");

// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
cout << "Got the handle!" << endl;
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "sum");

// If the function address is valid, call the function.

if (NULL != ProcAdd)
{
cout << "Got the function!" << endl;

fRunTimeLinkSuccess = TRUE;
k = (ProcAdd) (i, j);
}

// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}

When I run the program, I can get the handle to the DLL, but cannot get
the function pointer to the DLL.

BTW, I copied the files (.cpp, .def) from VC++ to CDT.

Thanks for your help.

Steve
Previous Topic:when use CDT, what files to add to source control (CVS/SVN)?
Next Topic:How to use static library in Managed Make C++ project?
Goto Forum:
  


Current Time: Tue Sep 16 21:39:39 EDT 2025

Powered by FUDForum. Page generated in 0.04448 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top