Thread: calling MS visual c++ dll in Borland 5.02

  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    6

    calling MS visual c++ dll in Borland 5.02

    Hello everyone,
    What I have is a dll created in Microsoft Visual C ++ and I would like to call it from a legacy application written using Borland 5.02. I have been trying to figure out why my C app keeps crashing. I have posted more detail and my code here -> https://forums.embarcadero.com/threa...93009&tstart=0 . I am able to see the the function loading using the GetProcAddress(), but when I attempt to call it, the program crashes. I am trying to use explicit linking, but am open to the idea of implicit linking if it will work.
    Any input towards this issue is appreciated.

    thanks in advance,

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you should check the calling conventions of the functions from your dll

    They should match in teh code where the functions are defined and where they are called.

    When dll is compiled by one compiler and called from the code - compiled by another do not expect the default calling conventions will match - declare them explicitely
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Sep 2013
    Posts
    6
    Hello vart,
    Thanks for the response. I have tried to make the functions calls match the dll. I have even updated the link I provided with the changes. However, I still get the crash in the same place. Do you know what else could be happening?

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you still using default call conventions - which could be different between 2 compilers - add _stdcall to the function declaration to specify it explicitly

    __stdcall
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    You appear to be confused are you using a C DLL or a C++ DLL?

    A C DLL is easier to get to work between two different compilers.

    I have no idea if a C++ DLL is possible; not sure stdcall will turn off C++ Name mangling or not. I am a C Programmer; so, my C++ knowledge is lacking.

    Tim S.
    Last edited by stahta01; 09-26-2013 at 11:16 AM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  6. #6
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by stahta01 View Post
    You appear to be confused are you using a C DLL or a C++ DLL?

    A C DLL is easier to get to work between two different compilers.

    I have no idea if a C++ DLL is possible; not sure stdcall will turn off C++ Name mangling or not. I am a C Programmer; so, my C++ knowledge is lacking.

    Tim S.
    To "turn off" C++ mangling function should be declared as extern "C"
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  7. #7
    Registered User
    Join Date
    Sep 2013
    Posts
    6
    @vart: thanks for the link. I appreciate your input.
    I have updated using the __stdcall (updated the https://forums.embarcadero.com/threa...597503&#597503 . see tag (updated)) . however, I still get the crash. I am able to verify the RVA is what I expect to see from the dump file I created using Borland's TDUMP utility and the exported function name is NOT mangled since I use the Extern "C" to switch off name mangling by Visual C++.
    Last edited by john12; 09-26-2013 at 01:37 PM.

  8. #8
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Just a sec. Looking at the C++ code - is it a managed C++?

    To call managed code from Unmanaged code and passing parameters - you need marshaling. Your native types should be translated properly into .Net types...

    I do not know the exact syntax for declaring such functions...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  9. #9
    Registered User
    Join Date
    Sep 2013
    Posts
    6
    hello vart,
    I am calling managed code (contained in the Dll) from the C application. I have been looking at this tutorial from MSDN:Managed Extensions for C++ and Data Marshaling Tutorial . Will keep this post updated the best I can.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows Api calling in[ Borland C ]
    By maj0 in forum C Programming
    Replies: 2
    Last Post: 03-25-2010, 03:42 AM
  2. Borland to Visual Studio
    By Halo in forum C++ Programming
    Replies: 4
    Last Post: 12-14-2005, 02:27 AM
  3. Calling raw windows API using borland
    By TiMBuS in forum C++ Programming
    Replies: 3
    Last Post: 06-16-2005, 08:46 AM
  4. Visual C++ and Borland C++ Builder :: Breakdown
    By kuphryn in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 02-24-2004, 04:53 PM
  5. Why does it work in Visual Studio and Not Borland
    By MonteMan in forum C++ Programming
    Replies: 14
    Last Post: 10-20-2002, 09:36 PM

Tags for this Thread