Solved

simple import/export problem

Posted on 1998-12-27
1
227 Views
Last Modified: 2010-04-02
hi,
I have 2 functions, SendMsg and Main.
I need to declare SendMsg as a dll and Main as a normal win32 console application and then export SendMsg out to Main.

I declare in the following ways:

for SendMsg
-----------
#define DLLExport __declspec(dllexport)
DLLExport int SendMsg()
{
      // do something
}

for main
--------
#define DLLImport __declspec(dllimport)
extern DLLImport int SendMsg();

void main()
{
      cout<<"sending msg using dll"<<endl;
      int results = SendMsg();
}

I added sendmsg.dll as one of the files in Main for building. And I encountered this problem:

main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int __cdecl SendMsg(void)" (__imp_?SendMsg@@YAHXZ)
Debug/appa.exe : fatal error LNK1120: 1 unresolved externals

Pls advise what have I missed out?

Thanks,
Andrea
0
Comment
Question by:tanmh
1 Comment
 
LVL 2

Accepted Solution

by:
zyqwert earned 10 total points
ID: 1181107
To implicitly link like this, you need to include sendmsg.lib in the project main, you do not need sendmsg.dll.

1) Remove SendMsg.dll from project main.
2) Add SendMsg.Lib to project main.

Let me know if there is any problem.



0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now