Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Creating a DLL

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
#include

#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?

Comments

  • LetsLearnThisLetsLearnThis Posts: 16Member
    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?
  • LundinLundin Posts: 3,711Member
    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.
  • TaylorQiTaylorQi Posts: 3Member
    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?
    :

  • bosebonasbosebonas Posts: 87Member
    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.
Sign In or Register to comment.