Thread: Can call one function, but not the other

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

    Can call one function, but not the other

    I'm creating a C++ MFC dll using Visual Studio 2005.
    I can call "CALCCMR" successfully from a dll, but not "CALCCLOGP". Here's the code that calls the dll:
    Code:
    // 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;
    In my main function, I follow the directions provided with the 3rd party dll:
    Code:
    //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");
    The instructions show how to call these function, but leave out/not explain some of the variables being passed. For example, there is no reference to a variable named Smiles. However, this is the value being passed to the dll, so if I hard-code it, it works when I try calcCMR(Smiles, &pCMR):

    Code:
    long err;
    float pCMR;
    
    err = calcCMR("O=C", &pCMR);
    I run this and it compiles fine.

    Here's the example for calculating calcLogp:

    Code:
    float pLogP;
    long err;
    
    long pNumContrb;
    
    // 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);
    When I compile this, I get the following errors:
    Code:
    c:\documents and settings\epajn\my documents\visual studio 2005\projects\cfx_clogp\request.cpp(62) : error C2065: 'LogPContribution' : undeclared identifier
    c:\documents and settings\epajn\my documents\visual studio 2005\projects\cfx_clogp\request.cpp(62) : error C2065: 'pClogPContrb' : undeclared identifier
    c:\documents and settings\epajn\my documents\visual studio 2005\projects\cfx_clogp\request.cpp(62) : error C2065: 'pclogp' : undeclared identifier
    There is no other additional information about the type for these variables, and I'm new to C++ so don't know what I'm missing.
    I've tried declaring these variables according to what's being imported, but still get errors. Does anyone have any insight?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > // Note: These MUST be GlobalFree( ) 'd after calls to calcLogP
    > LogPContribution** pClogPContrb, * pclogp;
    You don't specify a type

    It looks like LogPContribution should be a type, but the error message suggests otherwise.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    80
    That's what I thought, but the types for LogPContribution, pClogPcontrb and pclogp were not provided in the instructions. I tried the following:
    Code:
    float pLogP;
    long err;
    
    long pNumContrb;
    long LogPContribution;
    long pClogPContrb;
    float pclogp;
    
    // Note: These MUST be GlobalFree( ) 'd after calls to calcLogP
    LogPContribution** pClogPContrb, * pclogp;
    
    
    pLogP = -99.99f;
    pNumContrb = 0;
    
    err = calcLogP("O=C", &pLogP, &pNumContrb, &pClogPContrb);
    Here are the errors:
    Code:
    c:\documents and settings\epajn\my documents\visual studio 2005\projects\cfx_clogp\request.cpp(65) : error C2100: illegal indirection
    c:\documents and settings\epajn\my documents\visual studio 2005\projects\cfx_clogp\request.cpp(65) : error C2100: illegal indirection
    c:\documents and settings\epajn\my documents\visual studio 2005\projects\cfx_clogp\request.cpp(71) : error C2664: 'CALCLOGP' : cannot convert parameter 4 from 'long *__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(71) : 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(71) : 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
    The directions seem to be missing information, does this sound correct? I want to request clearer directions, but want to make sure the current directions aren't workable.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You're passing the function (const char *, float *, long *, long *) and it's expecting otherwise.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    I would comment out this line, because it makes no sense
    // LogPContribution** pClogPContrb, * pclogp;

    Also, you need to add comments to your code snippets, because there's no way for us to match line numbers in your error messages to lines of code you post.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM