Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling C++ dll 1

Status
Not open for further replies.

buddm

Programmer
Oct 20, 2003
5
US
Does anyone know how to compile,link, and then call a C++ dll and it's functions if you do not have a "lib" import file for the dll?
 
You either get the .lib from the manufacturer of the DLL or you dissassemble the DLL.

There is a tool on the net that allows you do do this, and you end up with a list of functions and it's parameters.
look for IDAPRO at

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Thanks Frederico, but I already have a detail breakdown of the functions and parameters from the vendor of the dll. My problem is when I call the 1st function, I get error JMP0015I-U, and yet the dll is in my program directory and my win/system32 directory which are both in my PATH. I need to link the dll to my program without having the LIB file. Or a way to call the dll and not have it abort.
 
If your vendor has supplied with the function list then he will not have any problem in supplying the .lib also.

You don't need the .lib, but that will mean that you will have the programs statically linked with the DLL, and this is not normally advisable.

I will not be able to help further on this until next weekend, but I am pretty sure that if you include the .dll instead of the .lib it will work fine.

You may still need to add some extra info to the .cbi (or .cbr??) file in order for your program to know where to load the functions from.




Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Frederico,

1st, the vendor does not have a LIB file for the dll, nor is he willing to create one. It actually was created with DELPHI, not C++.

2nd, if I compile my program with NODLOAD to make it static linkage, it fails to link "unresoloved references". if I compile it with DLOAD, it links, but fails to execute. I already created an Entry Information file and added it to the @CBR_ENTRYFILE into my cobol85.cbr.
 
Frederico,

I guess I'm dense on this, but I create my app in the Project Manager, and as far as I can find there is now way to link a "dll" file to the application.
 
Hum. There is a way, but as I don't have access to FJ until the weekend I won't be able to help you with exact details.

In one of the menus you have a link and a compile options. Using the link one you have an option to add options to the LINK step. try and dig around it.

The online help should also give you a quick help with it.


Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
buddm,

here is an example in Fujitsu cobol. It calls MessageBoxA, which is in user32.dll, without needing to link user32.lib. The three static calls, LoadLibraryA, GetProcAddress and FreeLibrary, are in kernel32.lib which is by default always linked in.

NOTE: Does NOT compile on Fujitsu 3.0 (the free one), because that version doesn't know the PROCEDURE-POINTER type. But it does compile and run using Fujitsu 6.1. Don't know about other versions.

Code:
       IDENTIFICATION DIVISION.
       PROGRAM-ID. TESTCALL.

       ENVIRONMENT DIVISION.

       DATA DIVISION.

       WORKING-STORAGE SECTION.
       77  HMODULE PIC 9(09) COMP-5 VALUE 0.
       77  HADRES  PIC 9(09) COMP-5 VALUE 0.
       77  HADRESP REDEFINES HADRES USAGE PROCEDURE-POINTER.
       77  HLIB    PIC X(08)        VALUE "user32"      & X"00".
       77  HTEKST  PIC X(08)        VALUE "tekst"       & X"00".
       77  HTITEL  PIC X(08)        VALUE "titel"       & X"00".
       77  HMSGB   PIC X(12)        VALUE "MessageBoxA" & X"00".

       PROCEDURE DIVISION.
       MAIN SECTION.
       M1.
           CALL "LoadLibraryA" WITH STDCALL LINKAGE
                               USING BY REFERENCE HLIB
                               RETURNING HMODULE.
           IF  HMODULE = 0
               DISPLAY "HMODULE == 0"
               GO TO M9.
           CALL "GetProcAddress" WITH STDCALL LINKAGE
                                 USING BY VALUE HMODULE
                                       BY REFERENCE HMSGB
                                 RETURNING HADRES.
           IF  HADRES = 0
               DISPLAY "HADRES == 0"
               GO TO M9.

           CALL HADRESP WITH STDCALL LINKAGE
                        USING BY VALUE 0
                              BY REFERENCE HTEKST
                              BY REFERENCE HTITEL
                              BY VALUE 0.

       M9.
           IF  HMODULE NOT = 0
               CALL "FreeLibrary" WITH STDCALL LINKAGE
                                  USING BY VALUE HMODULE
               MOVE 0 TO HMODULE.
           STOP RUN.


Marcel
 
Merci, Marcel. I was just about to research how to do this - though using a different compiler. Saved me time.

Dimandja
 
MKuiper,

We're getting closer I think, however, I am still on version 5 and it does not allow "Procedure-Pointer" usage !

Thanks for the help none the less.

Budd
 
Dimandja,
glad it helped.

Budd,

I know no other way to do this in Fujitsu Cobol alone.
But, if you have a C++ compiler (or perhaps Visual Basic, I don't know that language) there are some options left:

1. Create a dll in C++ calling functions from the dll you want. This will also create a .lib file. Call your own functions from your Cobol program and include your .lib when linking it.

2. (Haven't tried this myself, but I think it should work:)
Suppose you want to call SomeFunction from SomeDll.dll
- create a C++ source somedll.cpp
- Make a function SomeFunction in it. What this function is doing doesn't matter, it may return immediately.
- compile it as a dll, it will also generate somedll.lib
- throw away the generated somedll.dll and keep the generated somedll.lib.
- include this somedll.lib when linking your cobol program
- Run your cobol program using the original somedll.dll

3. If you do not have another language available: I have written a dll in C++, which is able to call any function from any dll, it can be called from any Fujitsu program compiled with 3.0 or above. If you want to have this .dll and .lib, please email at marcel.kuiper-nospam@home.nl, without -nospam of course.


Marcel
 
Budd,

the email I sent back was bounced (access denied error)
I sent a message to your alternate email address, which seemed to be blocked by a spamfilter. So I don't know if one of the emails was delivered. Please let me know if not.


Marcel
 
There is a way to generate a .lib file reading from a dll.
Try to download an evaluation version of "DLL to Lib" from ...It should help you to generate a .lib file to include in the project..

Hope in this help.

Gianni
 
DO NOT PAY for it.

If you download the following product from Borland (free) you have an utility (IMPLIB.EXE) that creates a .lib from a DLL( being it a .DLL, .EXE or .DRV).

ftp://ftpd.borland.com/download/bcppbuilder/freecommandLinetools.exe


Now that I have my hands on my FJ I don't see a way of compiling a .DLL withouth the .LIB, so you will need to create this. See the above utility and try it.



Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top