Calling C DLL from VB

Discussion in 'C Programming' started by Nick, Nov 14, 2003.

  1. Nick

    Nick Guest

    I have read many postings regarding the above thread but don't seem to
    have found the exact problem I am experiencing.

    I am using VS.NET and have 2 projects within the 1 solution. First
    project is a VB module (compiled to .EXE) and is the calling module.
    The 2nd project is C and compiles to a DLL.

    The DLL takes the definition of an ARC(4 Points) and converts this
    geographically into a string of Points. The DLL was written in C
    because of the math and speed requirements.

    Here is the declare in VB:
    Declare Function ConvertArctoString Lib "convarc.dll" Alias
    "_ConvertArctoString@8" (ByVal sDir As Short, ByVal ParamArray
    allPts() As AspMap.Point) As Integer

    Here is the declare in C module:
    #define CONVARC_API __declspec(dllexport)
    CONVARC_API long PASCAL ConvertArctoString (long, PPOINTD);

    The problem I am having is:
    1. C DLL does not appear to load when I view the Modules window.
    2. Can place a breakpoint in C source but when I DEBUG VB EXE the
    breakpoint
    in C module never reached and the IDE reports that no symbol
    information could be found!
    3. I get a GPF when I start assigning the coordinate x and y values in
    the DLL with above declare. Cant use ByRef with ParamArray.
    4. If I do NO assignment the VB variable appears to have been nulled
    on return from the DLL!!

    In light of this wrote simple function.
    Here is the code:
    CONVARC_API long PASCAL ArcStart2(PPOINTD arcPts)
    {
    arcPts[0].x = 999.0;
    arcPts[0].y = 999.0;
    return arcPts[0].x/2;
    }

    and the DECALRE/call from VB module:
    Declare Function ArcStart2 Lib "convarc.dll" Alias "_ArcStart2@4"
    (ByRef iPts As AspMap.Point) As Integer
    Dim testPt As New AspMap.Point()
    iNumPts = ArcStart2(testPt)

    interestingly iNumPts gets returned with 499 so appears the assignment
    works but the variable testPts gets set to "Nothing" on return from
    DLL.

    Am lost without debug and not sure how to get DLL to load. I can't
    add as a reference in the VB project as I get an error saying it is
    not a valid .NET assembly!
     
    Nick, Nov 14, 2003
    #1
    1. Advertising

  2. Nick

    Jack Klein Guest

    On 13 Nov 2003 18:51:35 -0800, (Nick) wrote
    in comp.lang.c:

    > I have read many postings regarding the above thread but don't seem to
    > have found the exact problem I am experiencing.


    This is a Windows issue, not a C language issue, and you need to ask
    about in one of the Microsoft support groups in the
    news:microsoft.public.* family somewhere.

    The C language does not define or support any of DLLs, .net, or VB.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c /faq
     
    Jack Klein, Nov 14, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anushi
    Replies:
    5
    Views:
    8,783
  2. Weston Fryatt
    Replies:
    2
    Views:
    976
    Weston Fryatt
    Jan 1, 2005
  3. NGM
    Replies:
    0
    Views:
    2,321
  4. Capsule

    calling c# dll from c++ dll

    Capsule, Oct 18, 2005, in forum: C++
    Replies:
    3
    Views:
    965
    Victor Bazarov
    Oct 18, 2005
  5. H. Simpson
    Replies:
    4
    Views:
    287
    H. Simpson
    Aug 3, 2004
Loading...

Share This Page