• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

simple import/export problem

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
tanmh
Asked:
tanmh
1 Solution
 
zyqwertCommented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now