Solved

Using MS DLLs in BORLAND

Posted on 1997-12-22
2
472 Views
Last Modified: 2008-02-07
I know that there is a lot of threads on this subject and I'm sure I've
read them all but I am still unable to get the MS DLL to work within a
BC++ form/application.  I am able to convert the COF -> OMF via the
modified .DEF file and create a .LIB.  This .DLL compiles at all stages
with no complaints BUT when the program is executed it complains that it
is not an NT executable even without a single function call to the
library has been made!!!!

********** SAMPLE CODE and PROCEDURE **********

**** MICROSOFT Definations used to create DLL:
extern "C" {
        __declspec(dllexport) int __stdcall OpenDB(char *DBName);
        __declspec(dllexport) int __stdcall CloseDB(void);
        __declspec(dllexport) int __stdcall OpenSQL(void);
        __declspec(dllexport) int __stdcall CloseSQL(void);
        __declspec(dllexport) HENV __stdcall henvGet(void);
        __declspec(dllexport) HDBC __stdcall hdbcGet(void);
}


**** BORLAND SIDE:
**** IMPDEF CREATES DBCONNECT.DEF:
LIBRARY     DBCONNECT.DLL

EXPORTS
    _CloseDB@0                    =_CloseDB                       @1
    _CloseSQL@0                   =_CloseSQL                      @2
    _FetchNext@0                  =_FetchNext                     @3
    _OpenDB@4                     =_OpenDB                        @4
    _OpenSQL@0                    =_OpenSQL                       @5
    _SelectSQL@8                  =_SelectSQL                     @6
    _hdbcGet@0                    =_hdbcGet                       @7
    _henvGet@0                    =_henvGet                       @8
    _hstmtGet@0                   =_hstmtGet                      @9

**** MODIFIED TO:
LIBRARY     DBCONNECT.DLL

EXPORTS
    _CloseDB@0                    =_CloseDB                       @1
    _CloseSQL@0                   =_CloseSQL                      @2
    _FetchNext@0                  =_FetchNext                     @3
    _OpenDB@4                     =_OpenDB                        @4
    _OpenSQL@0                    =_OpenSQL                       @5
    _SelectSQL@8                  =_SelectSQL                     @6
    _hdbcGet@0                    =_hdbcGet                       @7
    _henvGet@0                    =_henvGet                       @8
    _hstmtGet@0                   =_hstmtGet                      @9

IMPORTS
    CloseDB=DBCONNECT._CloseDB@0
    CloseSQL=DBCONNECT._CloseSQL@0
    FetchNext=DBCONNECT._FetchNext@0
    OpenDB=DBCONNECT._OpenDB@4
    OpenSQL=DBCONNECT._OpenSQL@0
    SelectSQL=DBCONNECT._SelectSQL@8
    hdbcGet=DBCONNECT._hdbcGet@0
    henvGet=DBCONNECT._henvGet@0
    hstmtGet=DBCONNECT._hstmtGet@0

**** IMPLIB CREATES DBCONNECT.LIB

**** Insert into project with the following:
USEDEF("DBConnect.def");
USELIB("DBConnect.lib");

**** Compile as release.

**** Execute program:

!!!!!!!!!!!! Message complains that it is not a an NT
Executable!!!!!!!!!!!!


HELP
Paul
0
Comment
Question by:wang_paul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Expert Comment

by:galkin
ID: 1256826
First be sure your DLL is regular DLL and not MFC extension DLL since extension DLL works only with MFC application.
Then try to load DLL dinamically and obtain  function addresses. If it woks try to create lid file from DLL using importlib utility instead of VC++ linker.
0
 
LVL 32

Accepted Solution

by:
jhance earned 100 total points
ID: 1256827
This is a nasty problem since Borland and MS use different and incompatible C++ name decoration schemes.  My advice is to forget using the exported names and call the DLL exported function by their ordinals instead.  This will work regardless of the produces of the DLL.  It's a bit more work up front but will work in all cases.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question