views:

1134

answers:

1

I am experiencing Frustration ^ Frustraion with this %&$^& VS IDE. I am using Visual C++ 2008 3.5 SP1 (but I also have the pro edition if that is needed and I dont want to use loadlibrary())

I have a test Dll created in another language (basic not C in fact) that contains a CDECL function that adds an 'int' to a 'double'. I would really like to add an int to a float using STDCALL, but if can get the former to work first that would be a major acheivement.

I have read extensively and tried: http://support.microsoft.com/kb/313981 http://www.codeproject.com/KB/DLL/loadingdll.aspx http://stackoverflow.com/questions/530420/linking-to-a-static-lib-that-links-to-a-static-lib http://stackoverflow.com/questions/996175/statically-and-dynamically-linking-dlls-generated-with-different-versions-of-visu

I wrote a nice header file for the AddShow.dll called AddShow.h

DLLAPI int __cdecl AddTwoNum(int n, double f);

Then I used this nifty tool to create the .lib file: http://www.binary-soft.com/dll2lib/dll2lib.htm

Now what?

I tried right click and 'Add' then 'Class" then 'Componant Class' then specifying the path and name of the dll, but I get 8 miles of bloat and the entire windows toolbox and a new AddShow.cpp file.

My C++ code is really simply:

extern int __cdecl AddTwoNum(int n, double f);

int main()
{
    int n, RetVal;
  double d;

     n = 33;
     d = 66.6;

    RetVal = AddTwoNum(n, d);

    cout << "RetVal=" << RetVal;

    return 0;
}

How do I just get the IDE to link the .lib file?

ADDED:

after linking (.lib file is in the debug file) I get the following error:
Compiling...
main.cpp
Linking...
main.obj : error LNK2019: unresolved external symbol "int __cdecl AddTwoNum(int,double)" (?AddTwoNum@@YAHHN@Z) referenced in function _main
C:\C++\FirstDll\Debug\FirstDll.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\C++\FirstDll\FirstDll\Debug\BuildLog.htm"
FirstDll - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
+2  A: 

You can go to:

Project Properties -> Linker -> Input

Then add your .lib to the "Additional Dependencies".

Additionally, you can put

#pragma comment(lib, "<your .lib>")

in your .cpp file.

Kevin
thank you for that but I get the compile error shown above.
Mike Trader
In your error, the name of AddTwoNum is mangled (?AddTwoNum@@YAHHN@Z)Try to put your AddTwoNum declaration in the brackets of a extern "C" { }
Kevin