C++ Builder

Moderators: Lundin
Number of threads: 509
Number of posts: 1146

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Creating a DLL Posted by LetsLearnThis on 6 Sept 2007 at 4:41 PM
1) I'm using the Borland C++ verision

I go to FILE >> New >> OTHER and choose Dynamic Link Library
2 Files Pop Up. Project1 and Unit1.cpp

With the .cpp file I rename it as TestDLL.cpp, below is the following code:

int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------

void __stdcall SayHello(void)
{
PRINTF("Hello");
}

then I create a .h file called TestDll.h, code is the following
#ifndef MAIN_DLL_UNIT_H
#define MAIN_DLL_UNIT_H

#ifdef __cplusplus
extern "C"
{
#endif
__declspec(dllexport) void __stdcall SayHello(void);

#ifdef __cplusplus
};
#endif /* __cplusplus*/
#endif /* MAIN_DLL_UNIT_H */


Then I open a console application
#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused
#include <stdio.h>
#include <conio.h>

#include "MainDLLUnit.h"

int main(int argc, char* argv[])
{
SayHello();
getch();
return 0;
}

I get the following error "Unresvoled external 'SayHello' referecned..."

what am I doing wrong?
Report
Re: Creating a DLL Posted by LetsLearnThis on 6 Sept 2007 at 5:25 PM
I was reading in the book that you have to compile the DLL and you'll find a .lib file. I am not getting a .lib file. What could be wrong?
Report
Re: Creating a DLL Posted by Lundin on 7 Sept 2007 at 7:25 AM
That is correct. A .lib file is a file statically linked to the project at linking time, while a dll is something you open in runtime with LoadLibrary(). I don't think that Borland will give you a .lib unless you ask for one explicitly. I don't remember how to fix this... no doubt with some hard-to-find linker setting. The easy solution would be to create a new static library project and have the IDE setting the linker settings for you.

That is, unless you want a dll. In that case you have to rewrite your main() program.
Report
Re: Creating a DLL Posted by TaylorQi on 22 Oct 2007 at 12:41 AM
Use command "implib xxx.lib xxx.dll" to get a .lib file.
: I was reading in the book that you have to compile the DLL and
: you'll find a .lib file. I am not getting a .lib file. What could
: be wrong?
:

Report
Re: Creating a DLL Posted by bosebonas on 22 Oct 2007 at 1:24 AM
I am sure you did not do the right thing.
In the menu file >new choose other,in the window that appears at that moment
choose wizard.another window appears.
There you will create your Dll.
Normally when you compile,check that the compilation options and the options of the projects enable creating a DLL.
The compilation should yield a .lib that can be statically linked and a .dll.
Also check that you created a .def file containing the entry points and enumerations of the functions.Though its not that necessary.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.