Solved

simple import/export problem

Posted on 1998-12-27
1
218 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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PCH Sample and Makefile 14 70
Visual c++ and text files 7 55
I could not build boost code, 10 50
Best book to learn C++ 4 52
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

743 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