Results 1 to 7 of 7

Thread: C dll for vB

  1. #1

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    C dll for vB

    I want to recode an algorithm in my vb-program in c/c++ for faster execution. I think a dll is the only way to do that. But I have many problems using the vB "Declare" directive, so my quesiton is: is there an easy way to link into vBs COM? Is there maybe a predefined skeleton that provides functions to vB where I can simply write my function and register it?
    This is something urgent, so plz help quick!
    CornedBee

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You don't need to register non-COM DLLs. Just code the function in C, and write a Declare for it.

    If you search this forum for "Declare" (use my username) I made a long post about it.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    i can't find the post, maybe you can supply a link?
    or tell me exactly what i have to type in the search form
    thx
    CornedBee

  4. #4

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Unhappy

    Ok, now i have a basic dll (like your testdll) up and running.
    Now on to the real problem: why can't I change an argument passed with ByRef, like in this sample:

    C:
    PHP Code:
    void STDCALL reffunc(longpArg)
    {
        
    // output *pArg, correct value
        
    *pArg 100;
        
    // output *pArg, correct value

    vB:
    Code:
    declare sub reffunc lib LIBNAME (ByRef arg as Long)
    
    private sub command1_click()
        dim i as long
        i = 20
        reffunc (i)
        // output i, still 20 :(


    I have no idea why this happens, it seems that the ByRef call still allocates a copy of the parameter

    CornedBee

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    How about trying something like this:
    Code:
    declare sub reffunc lib LIBNAME (ByVal pArg as Long)
    
    ' ...
        dim i as long
        i = 20
        reffunc VarPtr(i)
    '...
    This time, it's passing a Long value directly, using the return value of VarPtr which is like C's & operator: VarPtr(i) = &i
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Thumbs up

    Thanks alot!
    This works, and it even works with arrays!
    You da man!!!!

    Or, like those at the js-forum would put it:
    -> ->

    (/me builds a shrine for parksie)

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Hehe thanks Always nice to be appreciated

    Actually, whenever pointers are needed I always pass a Long by value (ByVal) using VarPtr (I'm still undecided on whether StrPtr does much different).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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