CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Callin C dll

  1. #1
    Join Date
    Jan 2011
    Posts
    1

    Smile Callin C dll

    Hi,

    I'm trying to write a VB6 program to communicate with a C dll.

    In C the function is defined as follows:


    /* You may need to construct a directory path in front of df_main.dll */
    theDLL = LoadLibrary("df_main.dll");
    theFunc = (DLLPROC)GetProcAddress(theDLL, "mbedEntryPoint")));

    /* Call DF engine */
    retStr = (*theFunc)(cmd);
    if (!strnicmp(retStr, "error", 5))
    ReportError(retStr, 0);
    else
    ...

    I have no clue, after several tries, how to address this function. Any ideas?

    Greetings,
    Steven

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Callin C dll

    VB6 doesn't have pointers, if that's what you want to know.
    Code:
    c:\folder\file
    is how you refer to a folder when you know where it is

    and when you don't

    Code:
    App.Path & "\folder\file"
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Callin C dll

    I'm afraid you can't call that function as-is from VB. Assuming the cmd parameter passed to the DLL function in your code sample is a usual C string (char * in C) you can pass it from VB; you'd just need to specify it as ByVal in the VB parameter list of the DLL function. But the return value from the DLL (assigned to retStr in the sample code) seems to be a char * (pointing to a C string) as well, and AFAIK it can't be passed back to VB that way.

    Therefore you would likely need to either change the DLL function or write a wrapper function (inside the DLL in question or another one) that then is to be called from VB.

    This thread may contain interesting background information on that topic for you: http://www.codeguru.com/forum/showthread.php?t=500031. The VB program discussed there is Excel VBA and the DLL in question is written in assembly language, but that doesn't make a difference for calling the DLL function.

    Please use code tags when posting code.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured