timb00 0 Newbie Poster

Hallo everybody,

I'am a newbe in the subject of dynamic-link library an c++. Currently I'am working on an interface of a fortran dll to c++ programm. I have available a example interface in Fortran, which works very well. My idea is to develop a one to one correspondent c++ source code. But the source code I developed didn't work.
Maybe someone could help me with the comparison of the souce codes.

Here are the source codes :

fortran :

PROGRAM POLYDYN
	use dflib
	use kernel32
    	interface
        SUBROUTINE POLYDYN6014(IIN,ICHANNEL1,ICHANNEL2,IOUT)
        !DEC$ ATTRIBUTES DLLEXPORT::POLYDYN6014
        ! Variables
        integer(4),intent(IN),dimension(128)::iin
        integer(4),intent(out),dimension(128)::iout
        integer(4),intent(OUT)::ICHANNEL1
        integer(4),intent(OUT)::ICHANNEL2
		end subroutine POLYDYN6014
    end interface

    integer(4),dimension(128)::in,iout
	logical(4) result1,result2
	INTEGER :: IEXIT=0,iarg
	integer p4
	pointer (q4,POLYDYN6014)
	result1= makedirqq("output")
	IF (result1) THEN
	write(*,*) 'New subdirectory OUTPUT successfully created'
	END IF
	result1= makedirqq("hpgl")
	IF (result1) THEN
	write(*,*) 'New subdirectory HPGL successfully created'
	END IF
	!
		do	
	write(*,*)"TRY LOAD...POLYSOLV6DLL.dll"
	p4 = loadlibrary("POLYSOLV6DLL.dll"C)
	if(p4/=0)exit
	enddo
	if (p4 == 0) then
		write(*,*)"Error occurred opening POLYSOLV6DLL.dll"
		write(*,*)"Program aborting"
		call exit(-40)
    else
		write(*,*)"POLYSOLV6DLL.dll LOADED"
	endif
        q4 = getprocaddress(p4, "POLYDYN6014"C)
	if (q4 == 0) then
		write(*,*)"Error occurred finding POLYDYN6014 in POLYSOLV6DLL.dll"
		write(*,*)"Program aborting"
		call exit(-41)
	endif
!       
        write(*,*)"INPUT CODE:",IN
        CALL POLYDYN6014(IN,ICHANNEL1,ICHANNEL2,IOUT)
        write(*,*)"OUTPUT CHANNEL1:",ICHANNEL1
        write(*,*)"OUTPUT CHANNEL2:",ICHANNEL2
        write(*,*)"PROGRAM EXECUTION CODE:",iout
        pause "END EXECUTION"
    END PROGRAM POLYDYN

and my c++ source code:

#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <stdlib.h>


    using namespace std;




int main(int argc, char *argv[])
{
 

    typedef void (*POLYDYN)(int *,int *, int *, int *);
    POLYDYN poly;
    HINSTANCE Hdllhp;
    
	
	int *I1,*I2,*c1,*c2;
	
	I1 = new int[128];
	I2 = new int[128];
	
	Hdllhp = LoadLibrary("Polysolv6dll.dll");
 
	if(!Hdllhp)
	{
		cout << "Missing DLL: your_DLL_name.dll" << endl;
		system("PAUSE");
		return FALSE;
	}
	cout << "GEKLAPPT !" << Hdllhp << endl;
  
	poly = (POLYDYN)GetProcAddress(Hdllhp , "POLYDYN6014");
	if (!poly)
	{
		cout << "Mißt !" << endl;
		system("PAUSE");
		return FALSE;
     }
      
	cout << "GEKLAPPT !" << poly << endl;
	system("PAUSE");
	(*poly)(I1,c1,c2,I2);
	cout << c1 << c2 << endl;
  
  
    system("PAUSE");
    return EXIT_SUCCESS;
}

Thanks for reading

Timb00

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.