Error C2664 - Trying to call an external Dll

This is a discussion on Error C2664 - Trying to call an external Dll within the C++ Programming forums, part of the General Programming Boards category; I'm using Visual Studio 2005 on Windows. I was supplied a third party dll that I need to call from ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    80

    Error C2664 - Trying to call an external Dll

    I'm using Visual Studio 2005 on Windows. I was supplied a third party dll that I need to call from an MFC DLL that I'm creating.

    I have a couple of questions.

    1. General Question
    The third party dll came with the dll named BB-CLOGP.DLL, a header file named clogp-dll.h and a folder named CLog P Data.
    Here's how I set the project up:
    Added clogp-dll.h in my project's main directory then added BB-CLOGP.DLL and the CLog P Data folder to the Debug folder where my dll is created when I compile the project. Does this sound correct?

    2. Specific Errors
    Here's the header file that came with the project:
    Code:
    // DH-20000401 moved RETURN_HANDLE define here
    // DH-20000323 updated struct field sizes
    // DH-19991005 initial version as per Kam Chana's specifications
    
    // define this if verbose results desired, otherwise only the calculated
    // value itself will be available to the calling function "CALCLOGP" which is imported around line 11 of my code
    
    // struct for ClogP results
    typedef struct {
    	char Class[10];
    	char Type[6];
    	char Description[40];
    	char Comment[10];
    	float Value;
    } LogPContribution;
    
    // struct for CMR results
    typedef struct {
    	char flag[1];
    	char atomType[3];
    	float atomValue;
    	int atomCount;
    	char bondType[18];
    	float bondValue;
    	int bondCount;
    } CMRContribution;
    Here's my code that tries to call the dll. Specifically, I'm trying to
    call the function CALCLOGP:

    Code:
    #include "stdafx.h"          // Standard MFC libraries
    #include "cfx.h"          // CFX Custom Tag API
    
    #include "clogp-dll.h"          // External CLogP DLL Header File
    
    // macros
    #define IMPORT extern "C" __declspec(dllimport)
    #define LINE_LIMIT 2048
    
    // import DLL functions
    typedef long (CALCLOGP)(const char*, float*, long*, HANDLE*);
    typedef long (CALCCMR)(const char*, float*);
    typedef long (CALCXMR)(const char*, float*);
    typedef long (CALCMGVOL)(const char*, float*);
    typedef long (MOL_FILE_IMPORT) (char* inputF, char* outputF);
    typedef double (CLOGP_VIA_MOL) (char* myMol);
    
    static CALCLOGP* calcLogP = NULL;
    static CALCCMR* calcCMR = NULL;
    static CALCXMR* calcXMR = NULL;
    static CALCMGVOL* calcMgVol = NULL;
    static MOL_FILE_IMPORT* mol_file_import;
    static CLOGP_VIA_MOL* clogp_via_mol;
    static HINSTANCE hinstCLogP = NULL;
    static HINSTANCE hinstCopy = NULL;
    
    void ProcessTagRequest( CCFXRequest* pRequest ) 
    {
         try
         {
            // Retrieve attributes passed to the tag          
            // For example: 
            //     LPCSTR lpszColor = pRequest->GetAttribute("COLOR") ;
              
    		//Complete the import of the dll routines
    		hinstCLogP = LoadLibrary("bb-clogp.dll");
    		hinstCopy = hinstCopy;
    
    		calcLogP = (CALCLOGP *) GetProcAddress(hinstCLogP, "calcLogP");
    		calcCMR = (CALCCMR *) GetProcAddress(hinstCLogP, "calcCMR");
    		calcXMR = (CALCXMR *) GetProcAddress(hinstCLogP, "calcXMR");
    		calcMgVol = (CALCMGVOL *) GetProcAddress(hinstCLogP, "calcMgVol");
    		mol_file_import = (MOL_FILE_IMPORT *) GetProcAddress(hinstCLogP, "mol_file_import");
    		clogp_via_mol = (CLOGP_VIA_MOL *) GetProcAddress(hinstCLogP, "clogp_via_mol");	
    
    		//Call the function to get the CLogP value
    
    		float pLogP;
    		long err;
    
    		long pNumContrb;
    
    		long smiles;
    
    
    		// Note: These MUST be GlobalFree( ) 'd after calls to calcLogP
    		LogPContribution** pClogPContrb, * pclogp;
    
    
    		pLogP = -99.99f;
    		pNumContrb = 0;
    
    		err = calcLogP(smiles, &pLogP, &pNumContrb, &pClogPContrb);
    
    		// smiles holds the smiles string of course.
    		// pLogP will have your value if err is less than 60.
    
    		// Later you must free as follows...
    		//	GlobalFree(pClogPContrb);
    		//	GlobalFree(pclogp);
    		 
    		 
    		 // Write output back to the user here...
              pRequest->Write( "Hello from CFX_HELLOWORLD!" ) ;
              // Output optional debug info
              if ( pRequest->Debug() )
              {
                   pRequest->WriteDebug( "Debug info..." ) ;
              }
         }
         // Catch Cold Fusion exceptions & re-raise them
         catch( CCFXException* e )
         {
              pRequest->ReThrowException( e ) ;
         }
         
         // Catch ALL other exceptions and throw them as 
         // Cold Fusion exceptions (DO NOT REMOVE! -- 
         // this prevents the server from crashing in 
         // case of an unexpected exception)
         catch( ... )
         {
              pRequest->ThrowException( 
                   "Error occurred in tag CFX_HELLOWORLD",
                   "Unexpected error occurred while processing tag." ) ;
         }
    }
    When I try to compile, I get errors regarding the parameters in the function call to
    err = calcLogP(smiles, &pLogP, &pNumContrb, &pClogPContrb); This is called around line 63

    The specific errors I get are:
    Code:
    c:\documents and settings\epajn\my documents\visual studio 2005\projects\cfx_clogp\request.cpp(70) : error C2664: 'CALCLOGP' : cannot convert parameter 4 from 'LogPContribution ***__w64 ' to 'HANDLE *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    c:\documents and settings\epajn\my documents\visual studio 2005\projects\cfx_clogp\request.cpp(70) : error C2664: 'CALCLOGP' : cannot convert parameter 3 from 'float *__w64 ' to 'long *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    c:\documents and settings\epajn\my documents\visual studio 2005\projects\cfx_clogp\request.cpp(70) : error C2664: 'CALCLOGP' : cannot convert parameter 1 from 'long *__w64 ' to 'const char *'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Generating Code...
    Additionally, the instructions do not declare the variable in parameter 1 anywhere (smiles).

    I'm assuming I can set it to a type of long

    I've been struggling with this for awhile so help is greatly appreciated.
    Last edited by jamez05; 03-08-2006 at 10:31 AM.

  2. #2
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    Code:
    typedef long (CALCLOGP)(const char*, float*, long*, HANDLE*);
    
    long smiles;
    float pLogP;
    long pNumContrb;
    LogPContribution** pClogPContrb
    
    
    err = calcLogP(smiles, &pLogP, &pNumContrb, &pClogPContrb);
    The error you receive is correct. See the declaration of your parameters do not match the typedef of the parameters that needs to be passed to function CALCLOGP
    First parameter needs to be const char* but you are putting a long (smiles)

    Hope it helps
    Amish

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    80
    Thanks Amish,

    I'm finally getting it to compile.

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    1
    Hello jamez05,


    I am working with this third-party BB-CLOGP.DLL too. Can sort of get the function calcLogP you are interested in to work, in the sense get valid CLogP values, in pLogP, for chemicals represented in smiles string, smiles. However, get null reference excepts due to pClogPContrb, which I throw away in driving code. (Basically don't think the contributions details in third party software, whatever these might be, are working properly.)
    The strange problem I having is that when driving code is VB.Net can get BB-CLOGP.DLL to work, but fails with access error, when driving code is VB6.
    This seems similar to another problem you were having, did you get this to work?

    Bye John S

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. call a non public dll method
    By aliem in forum Windows Programming
    Replies: 0
    Last Post: 05-17-2008, 04:51 AM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. c++ ISAPI fails to call VB dll
    By froque in forum Windows Programming
    Replies: 0
    Last Post: 08-22-2003, 03:06 AM
  4. Help needed with external call, WinExec() and timer.
    By algorithm in forum Windows Programming
    Replies: 9
    Last Post: 11-07-2001, 09:35 AM
  5. Pls help me to do this project in C I need source code
    By sureshmenon74 in forum C Programming
    Replies: 4
    Last Post: 10-04-2001, 07:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21