Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 485
  • Last Modified:

Using MS DLLs in BORLAND

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
wang_paul
Asked:
wang_paul
1 Solution
 
galkinCommented:
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
 
jhanceCommented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now