Re: [Dev-C++] =?utf-8?b?562U5aSNOiAg562U5aSNOiBIb3cgdG8gYnVpbGQgYSBE?= =?utf-8?q?LL_with_def_file=
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2006-08-09 11:41:13
|
I do dynamic loading of libraries in my applications too using something
like the following for Win32 applications. Normally I hide a bit more of
the code in macros, to make it work with Linux too.
#if BUILDING_DLL
#define DLLIMPORT __declspec(dllexport)
#else
#define DLLIMPORT __declspec(dllimport)
#endif
extern "C" {
DLLIMPORT DWORD __cdecl GetObjectFactoryCount();
DLLIMPORT bool __cdecl GetObjectFactory(DWORD n,ObjectFactoryInfo& info);
}
hLib =3D LoadLibrary(pszName);
GetObjectFactoryCount =3D
(suitable cast)GetProcAddress(hLib,"GetObjectFactoryCount");
GetObjectFactory =3D
(suitable cast)GetProcAddress(hLib,"GetObjectFactory");
/Per W
On Wed, 9 Aug 2006, HongQuan.Zhang wrote:
> Per Westermark=EF=BC=9A
> =09Thank you for answer my question.
> =09I don't want to use __declspec(dllexport),because this director will =
output a function name with additional characters which are added by compil=
er.
> =09Example:
> =09void=09Test(int a);
> =09maybe output like this "_test@4"
> =09I just want to output with name "Test" , So I can use LoadLibrary and =
GetProcAddress to get the function address easily!
> =09That is,I need to load the dll and invoke the function dynamicly!
>
> =09In MSVC ,I can only need to do is provide a def file and write the fun=
ction name down and compile!
>
> =09Anyway,thanks again!
>
>
>
> Hongquan
>
>
>
>
> -----=E9=82=AE=E4=BB=B6=E5=8E=9F=E4=BB=B6-----
> =E5=8F=91=E4=BB=B6=E4=BA=BA: Per Westermark [mailto:pw...@ia...]
> =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2006=E5=B9=B48=E6=9C=889=E6=97=A5 1=
7:48
> =E6=94=B6=E4=BB=B6=E4=BA=BA: HongQuan.Zhang
> =E6=8A=84=E9=80=81: Dev...@li...
> =E4=B8=BB=E9=A2=98: Re: [Dev-C++] =E7=AD=94=E5=A4=8D: How to build a DLL =
with def file=EF=BC=9F
>
> Note that in C++, the external name of functions are mangled. Extra digit=
s and characters are added to the name to distinguish type information. Thi=
s is needed since C++ allows multiple functions with the same name but with=
different signatures. For example:
>
> int Test() { return 0}
> int Test(int a) { return a; }
> int Test(int a,int b) { return a+b; }
> int Test(const char* s) { return strlen(s); } ...
>
> If you use a file to specify exported symbols, you have to specify the fu=
lly mangled name.
>
> Or, you have to declare the function as type "C", to avoid the name mangi=
ng. The function will then just get an initial underscore in it's external =
name - _Test.
>
> When developing on Windows systems, it is quite common to use the M$
> extension:
> __declspec(dllexport)
> before name of exported symbols directly in the source code.
>
> The linker will then be able to extract the information about all exporte=
d symbols automatically, without the need of the def file.
>
> You might have code:
>
> __declspec(dllexport) int my_variable;
> __declspec(dllexport) int Test() { return 0; } ...
>
> Normally the dll declaration is hidden in a #define, to make the code com=
patible with compilers/environments that doesn't support DLL files.
>
> #define __declspec(dllexport) EXPORT
>
> EXPORT int my_variable;
> EXPORT int Test() { return 0; }
>
>
> In the same way, code that needs to access a function or variable defined=
in a DLL may use __declspec(dllimport) instead.
>
> /Per W
>
> On Wed, 9 Aug 2006, HongQuan.Zhang wrote:
>
> > I am sorry that I haven't finish the post before I send it!
> > the original message is at below.
> > And I just want to know how to code the def file,or how to build a dll
> > with specify export function name!
> > Thanks a lot!
> >
> > Hongquan
> >
> > -----=C3=93=C3=8A=C2=BC=C3=BE=C3=94=C2=AD=C2=BC=C3=BE-----
> > =C2=B7=C2=A2=C2=BC=C3=BE=C3=88=C3=8B: HongQuan.Zhang [mailto:hongquan.z=
ha...@i-...]
> > =C2=B7=C2=A2=C3=8B=C3=8D=C3=8A=C2=B1=C2=BC=C3=A4: 2006=C3=84=C3=AA8=C3=
=94=C3=829=C3=88=C3=95 17:16
> > =C3=8A=C3=95=C2=BC=C3=BE=C3=88=C3=8B: 'Dev...@li....=
net'
> > =C3=96=C3=B7=C3=8C=C3=A2: How to build a DLL with def file=C2=A3=C2=BF
> >
> > Hi=C2=A3=C2=ACAll:
> > =09I create a dll project and I want to export some function such as
> > =09void Test();
> > =09I add a def file like def file in MSVC,and of course I add a linker
> > opiton "-def test.def"
> > =09 in project options->parameter->linker
> > =09In the file Test.def,there are only several code as follow:
> >
> > ; test.def : Declares the module parameters for the DLL.
> >
> > LIBRARY "test"
> > DESCRIPTION 'test Windows Dynamic Link Library'
> >
> > EXPORTS
> > ; Explicit exports can go here
> > Test
> >
> >
> > When I compile the project and get some error:
> > [Linker error] undefined reference to `Test'
> >
> >
> >
> >
>
>
>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job ea=
sier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronim=
o
> http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat=
=3D121642
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|