Solved

Using MS DLLs in BORLAND

Posted on 1997-12-22
2
456 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
2 Comments
 
LVL 7

Expert Comment

by:galkin
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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 opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now