Wierd dll function names

This is a discussion on Wierd dll function names within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to make a WIN32 dll but I doesn't compile right somehow. For example: Code: __declspec(dllexport) int testfun(int x) ...

  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,786
    you need to use "C" linkage to avoind C++ name mangling

    See here - Function Calling From A DLL In a DLL

  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,786
    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, 12: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, 03:30 AM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM
  5. Function Call From DLL
    By (TNT) in forum Windows Programming
    Replies: 5
    Last Post: 05-05-2002, 09:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21