Thread: call DLL function from another DLL

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    13

    call DLL function from another DLL

    Hey guys,

    my little programm doesn't seem to work - I assume it is caused by a mistake in the function declaration respectivly calling the function...

    The sitation is as follows:

    A Programm uses a DLL, respectivly its function EXPORT.
    In this function there is a link to another DLL. This one exposes 2 functions - INIT and CTRL, which have the following c-style declarations, using the CDECL calling convention:

    Code:
    void INIT(double *array1, double *array2);
    void CTRL double *array1, double *array2);
    Below you find the sourcecode from my DLL, with the function EXPORT:

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <windows.h>
    
    typedef void (__cdecl *CTRL)(double*, double*);
    typedef void (__cdecl *INIT)(double*, double*);
    	
    double dll1_in_array1[101]; //an array for both input and output             
    double dll1_out_array1[101]; //und for each function	
    double dll1_in_array2[101]; //these are tranferred to the functions
    double dll1_out_array2[101]; //later on
    
    INIT call_dll1_Init;
    CTRL call_dll1_Ctrl;
    		
    HINSTANCE hinstlib_dll1= LoadLibrary(L"DLL1.dll");		
    	
    extern "C" {
    void __declspec(dllexport) __cdecl EXPORT(float *var1,int *var2, char *var3, char *var4, char *var5);}
    
    
    void __declspec(dllexport) __cdecl EXPORT(float *var1,int *var2, char *var3, char *var4, char *var5)
    {
    	
    
    call_dll1_Init=(INIT)GetProcAddress(hinstlib_dll1,"INIT");	
    	
    call_dll1_Ctrl=(CTRL)GetProcAddress(hinstlib_dll1,"CTRL");	 
    
    
    .
    .
    .
    
    call_dll1_Init(dll1_in_array1,dll1_out_array1);	 //calling the functions
    	
    call_dll1_Ctrl(dll1_in_array2,dll1_out_array2);		
    .
    .
    .
    Implementation of the DLL works quite well. calling the functions, e.g.
    Code:
    call_dll1_Init(dll1_in_array1,dll1_out_array1);
    also seems to be working.

    But I am quite unsure, if for the cdecl calling convention
    Code:
    void INIT(double *array1, double *array2);
    the declaration
    Code:
    typedef void (__cdecl *INIT)(double*, double*);
    is correct, because

    Code:
    typedef void (__cdecl *CTRL)(double *input, double *output);
    causes no errors in compiling, too.

    Thanks for your replies.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Putting the parameter names in the typedef is optional, so both ways are correct.

    You say your program doesn't work, but what part is not working? Which function is failing?
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    13
    Quote Originally Posted by bithub View Post
    You say your program doesn't work, but what part is not working? Which function is failing?

    Well then intention is to send the input- and outputarrays

    Code:
    double dll1_in_array1[101]; //an array for both input and output             
    double dll1_out_array1[101]; //und for each function	
    double dll1_in_array2[101]; //these are tranferred to the functions
    double dll1_out_array2[101]; //later on
    using the function calls

    Code:
    call_dll1_Init(dll1_in_array1,dll1_out_array1);
    call_dll1_Ctrl(dll1_in_array2,dll1_out_array2);
    to the DLL functions,


    where the input-arrays cause a change of the outputarray, as the inputarray is changing permanently by the main program.

    But after initializing the functions and arrays (which DOES change the outputarray) nothing more seems to happen.

    So I was thinking, that the transfer of the inputarray is not working at all, maybe caused by an invalid call or type definition.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking to DLL without LIB and call it's function of stdcall
    By leiming in forum Windows Programming
    Replies: 2
    Last Post: 04-14-2010, 11:07 PM
  2. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 04:25 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Error C2664 - Trying to call an external Dll
    By jamez05 in forum C++ Programming
    Replies: 3
    Last Post: 08-08-2006, 06:07 AM
  5. Replies: 28
    Last Post: 07-16-2006, 11:35 PM