Thread: Wierd dll function names

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    11

    Wierd dll function names

    I'm trying to make a WIN32 dll but I doesn't compile right somehow. For example:

    Code:
    __declspec(dllexport) int testfun(int x)
    {
    	return x+1;
    }
    It compiles ok, but when i try to use testfun() from another program I get an error saying that that function doesn't exist in dll. I opened mydll.dll in DLL Viewer and it showed that that
    function exists and is called "?testfun@@YAHH@Z". So, I tried using ?testfun@@YAHH@Z() in my program and it works! But how can I make a dll that has a correct function name? I'm using Visual Studio .NET 2003.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    you need to use "C" linkage to avoind C++ name mangling

    See here - http://cboard.cprogramming.com/showt...ight=dllexport

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    11
    Ok, that works fine for functions. But, how do I declare/define classes so they have proper names?

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Have a read through this http://www.codeguru.com/Cpp/Cpp/cpp_...cle.php/c4017/

    I personally dont like exporting classes. If I want to encapsulate an object in a dll I like to use COM

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DLL function by ordinal
    By George2 in forum Tech Board
    Replies: 2
    Last Post: 02-07-2008, 01:08 AM
  2. Problem in returning value from the dll exported function
    By dattaforit in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2006, 04:30 AM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. Function Call From DLL
    By (TNT) in forum Windows Programming
    Replies: 5
    Last Post: 05-05-2002, 09:33 PM