Link to home
Start Free TrialLog in
Avatar of 468572
468572

asked on

Use VC++6.0 DLL in BC++5.2

Is it possible to build DLL in VC++6.0 and make it accessible by BC++5.2? Could you provide an example?
Avatar of AlexVirochovsky
AlexVirochovsky

Can ,it is possible. Dll is standart thing, and no matter
how you build it. But: Format of Debug information,
that can be in Dll is different in VC and BC.
This means, that you can't debug this Dll in symbol mode!
Example: standart example of using Dll ("SCPWDLL.DLL")

   const char szcScpWDLLName [] = "SCPWDLL.DLL"; //
   const char szcFuncName [] = "VERPROT";        //
   TModule  *ScpDLLModule;

   ScpDLLModule = new TModule ( szcScpWDLLName, TRUE);
   int FAR PASCAL ( *VerProtFun )( char * );
   ( FARPROC ) VerProtFun = ScpDLLModule ->
                      GetProcAddress ( szcFuncName );
   if ( VerProtFun )
     {
     }
   free (ScpDLLModule);
Avatar of 468572

ASKER

This doesn't work for me.
See following sample code.
//DLL built in VC++6.0
//---mydll.cpp---
#include "stdafx.h"
#include "mydll.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#pragma data_seg("SharedMemory")
   int data = 0;
#pragma data_seg()

DLLexport void WINAPI IncrementCounter()
{
      char text[80];
      sprintf(text, "New counter value of %d.", ++data);
      ::MessageBox(0,text,"",MB_OK);
}

//---mydll.h---
#if !defined(AFX_COUNTERDLL_H__A45E4A6E_A79A_11D1_887F_D42B07C10710__INCLUDED_)
#define AFX_COUNTERDLL_H__A45E4A6E_A79A_11D1_887F_D42B07C10710__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
      #error include 'stdafx.h' before including this file for PCH
#endif


#define DLLexport      __declspec( dllexport )
DLLexport void WINAPI IncrementCounter();

#endif // !defined(AFX_COUNTERDLL_H__A45E4A6E_A79A_11D1_887F_D42B07C10710__INCLUDED_)

//---the code I used in BC++5.2 to call the function in mydll.dll
          TModule  *ScpDLLModule = new TModule ( "mydll.dll", TRUE);
          void FAR PASCAL ( *entry )( void );
          ( FARPROC ) entry = ScpDLLModule ->GetProcAddress( "IncrementCounter" );
          if ( entry )
            {
              entry();
            }
          free (ScpDLLModule);

I always get entry == NULL.

I also tried to use implib in BC5.2 to create mydll.lib and link it to my exe but I got "unresolved external 'IncrementCounter()' referenced from ......."

By you data, after VC name of programm othen (not IncrementCounter). Can be "_" in Begin or case.
 For know this name you can use tdump programm,that
 print REAL exported name.
something as:
tdump mydll.dll my.lst

Avatar of 468572

ASKER

I have found the answer at the following inprise web site.
http://www.borland.com/devsupport/borlandcpp/ti_list/TI3242.html
468572! Thank for URL with this article, very interesting,
but may idea exectly as i think: VC generate name of Function other, than original. And I think, that best
way is not make def files, as in anm article, but(as i wrote)
1.use tdump for detect REAL name.
2. Use this real name in line
          ( FARPROC ) entry = ScpDLLModule ->GetProcAddress( "@IncrementCounter32" );
//for example
Best Regards, Alex
ASKER CERTIFIED SOLUTION
Avatar of AlexVirochovsky
AlexVirochovsky

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial