.lib C++ to DLL to use in Delphi

120 views
Skip to first unread message

Analia Urbano

unread,
Apr 28, 1999, 3:00:00 AM4/28/99
to
I have a .lib file for VisualC++ and I want to link it in a Delhpi project.
I read that I should write a dll that wrapps the .lib file.
I have no experience with Visual C++, could somebody send some code in C to
accomplish this?

Thanks
Analia Urbano
ana...@tangosoft.com.ar

Peter Below (TeamB)

unread,
Apr 29, 1999, 3:00:00 AM4/29/99
to
> I have a .lib file for VisualC++ and I want to link it in a Delhpi project.
> I read that I should write a dll that wrapps the .lib file.
> I have no experience with Visual C++, could somebody send some code in C to
> accomplish this?
>
Analia,

that is not a thing you can do with a generic piece of code. You need to
create a DLL project in VC++, write a C source file that defines a wrapper
function for each function of the lib you want to export, write a DEF file for
the project to export the wrappers with sensible names and compile the mess.

Start by making a copy of the header file that (hopefully) comes with the LIB,
rename it to mydll.c or whatever, go over the file and eliminate anything that
is not a function prototype. Put a

#include headerfilename.h

at the top (you may need to include more headers if the function prototypes
use API types, for instance, simply look at the #include directives in
the header file), then change the prototypes (you only need to keep those you
want to be accessible via the dll) to actual functions, renaming them by
adding a standard prefix, for example. Specify STDCALL as calling convention,
add a function body that simply calls the LIB function it wraps with the
passed parameters.


Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!


Analia Urbano

unread,
Apr 30, 1999, 3:00:00 AM4/30/99
to
Hello! Thanks for answering.

I get the following errors when I try to compile
Linking...
.\mymmc.def : warning LNK4017: MyMMCPropertyChangeNotify statement not
supported for the target platform; ignored
.\mymmc.def : warning LNK4017: MyMMCFreeNotifyHandle statement not supported
for the target platform; ignored
.\mymmc.def : warning LNK4017: MyMMCPropPageCallback statement not supported
for the target platform; ignored
mymmc.def : error LNK2001: unresolved external symbol exports
Debug/mymmc.lib : fatal error LNK1120: 1 unresolved externals
LINK : fatal error LNK1141: failure during build of exports file
Error executing link.exe.
mymmc.dll - 3 error(s), 3 warning(s)

What should I do?
The code of the cpp is:
// mymmc.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "windows.h"
#include "ole2.h"
#include "mymmc.h"
#include "mmc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


STDAPI MyMMCPropertyChangeNotify(long lNotifyHandle, long param)
{
return MMCPropertyChangeNotify(lNotifyHandle, param);
}
STDAPI MyMMCFreeNotifyHandle(long lNotifyHandle)
{
return MMCFreeNotifyHandle(lNotifyHandle);
}
STDAPI MyMMCPropPageCallback(void* vpsp)
{
return MMCPropPageCallback(vpsp);
}

////////////////////////////////////////////////////////////////////////////
/
// CMymmcApp

BEGIN_MESSAGE_MAP(CMymmcApp, CWinApp)
//{{AFX_MSG_MAP(CMymmcApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

////////////////////////////////////////////////////////////////////////////
/
// CMymmcApp construction

CMymmcApp::CMymmcApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}

////////////////////////////////////////////////////////////////////////////
/
// The one and only CMymmcApp object

CMymmcApp theApp;

the code for the .def is
; mymmc.def : Declares the module parameters for the DLL.

LIBRARY "mymmc"
DESCRIPTION 'mymmc Windows Dynamic Link Library'

EXPORTS
; Explicit exports can go here
exports MyMMCPropertyChangeNotify @1
exports MyMMCFreeNotifyHandle @2
exports MyMMCPropPageCallback @3

Thanks
Analia Urbano


Peter Below (TeamB) <10011...@compuXXserve.com> wrote in message ...

Analia Urbano

unread,
Apr 30, 1999, 3:00:00 AM4/30/99
to
I had an error in the mymmc.def,I had writeen exports before any function
decalration, now my def file is:

; mymmc.def : Declares the module parameters for the DLL.

LIBRARY "mymmc"
DESCRIPTION 'mymmc Windows Dynamic Link Library'

EXPORTS
; Explicit exports can go here

MyMMCPropertyChangeNotify @1
MyMMCFreeNotifyHandle @2
MyMMCPropPageCallback @3

But I have anothers errors:

Compiling...
mymmc.cpp
Linking...
Creating library Debug/mymmc.lib and object Debug/mymmc.exp
mymmc.obj : error LNK2001: unresolved external symbol
_MMCPropertyChangeNotify@8
mymmc.obj : error LNK2001: unresolved external symbol _MMCFreeNotifyHandle@4
mymmc.obj : error LNK2001: unresolved external symbol _MMCPropPageCallback@4
Debug/mymmc.dll : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.

mymmc.dll - 4 error(s), 0 warning(s)

After this I added the following line to mymmc.h
#pragma comment(lib, "mmc.lib")

but now I have this errors:
Linking...
Creating library Debug/mymmc.lib and object Debug/mymmc.exp
mmc.lib(apimfc.obj) : error LNK2001:
unresolved external symbol "public: __thiscall
AFX_MAINTAIN_STATE::~AFX_MAINTAIN_STATE(void)"
(??AFX_MAINTAIN_STATE@@QAE@XZ)
mmc.lib(apimfc.obj) : error LNK2001:
unresolved external symbol "class AFX_MODULE_STATE * __stdcall
AfxSetModuleState(class AFX_MODULE_STATE *)"
(?AfxSetModuleState@@YGPAVAFX_MODULE_STATE@@PAV1@@Z)
mmc.lib(apimfc.obj) : error LNK2001: unresolved external symbol "class
AFX_MODULE_STATE * __stdcall AfxGetStaticModuleState(void)"
(?AfxGetStaticModuleState@@YGPAVAFX_MODULE_STATE@@XZ)
Debug/mymmc.dll : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.

mymmc.dll - 4 error(s), 0 warning(s)


Any Suggestion, thanks

Analia Urbano


Analia Urbano wrote in message <7gcj2m$qi...@forums.borland.com>...

Analia Urbano

unread,
Apr 30, 1999, 3:00:00 AM4/30/99
to
Hello:
I chaged one project settings and it did compile,
I put in the general Setting: Use MFC in a shared DLL.

Thanks

Analia Urbano

Analia Urbano wrote in message <7gcn39$r5...@forums.borland.com>...

Peter Below (TeamB)

unread,
Apr 30, 1999, 3:00:00 AM4/30/99
to
In article <7gcj2m$qi...@forums.borland.com>, Analia Urbano wrote:
> What should I do?
>

Post your problem in one of the C-oriented newsgroups, perhaps
borland.public.cpp.language or borland.public.cppbuilder.language.
I'm not familar enough with VC++ and C/C++ in general to be able to
help you further.

Reply all
Reply to author
Forward
0 new messages