Results 1 to 10 of 10

Thread: Own API calls

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    4

    Unhappy

    Hi!
    Is it possible to make own API call liberys in VB? So i can make a function, compile it into a dll and then call it from another program with the declare function statement?
    //MVH takko

  2. #2
    Guest
    No. VB can only create ActiveX DLL's. In order to use a function in that respect, you need to use a Standard DLL. To make a standard DLL, use C++.

  3. #3
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    call c++ dll

    Is it possible to pass a variable into a MFC c++ dll.. if so could someone give an example of how to declare the dll and how to pass variable to it assuming it as only one parameter of type long

    Many thanks

  4. #4
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    c++

    Does anyone know how to alter code for a c++ dll to make it viewable to VB?

  5. #5
    Guest

    Re: call c++ dll

    Originally posted by gsc1ugs
    Is it possible to pass a variable into a MFC c++ dll.. if so could someone give an example of how to declare the dll and how to pass variable to it assuming it as only one parameter of type long

    Many thanks
    Use the Declare Function statement.
    Code:
    Declare Function MyFunc Lib "MyLib" (ByVal MyParam As Long) As Long

  6. #6
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    done

    Thanks but didn't work.. but master it in the end here's the solution.

    VB: Alias is the key calling the mangled function and byte size
    Declare Function CheckDongle Lib "D:\DEVELOP\ALL16_32\SetReg\Debug\SetReg.dll" Alias "_CheckDongle@4" (ByVal nDays As Integer) As Integer


    C++

    #ifdef __cplusplus
    extern "C" {
    #endif

    int __declspec(dllexport) CALLBACK CheckDongle(int lDays)
    {
    CDongle CInstDongle;

    return CInstDongle.OnSetRegistryEntries(lDays); //EXTENDS INTO CLASS DEFINITION
    }

    #ifdef __cplusplus
    }
    #endif

  7. #7
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    but still have related problem

    I would like to pass a long value thru this function but VB as a fit.. anyone tell me a work around? int are fine

  8. #8
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    guru's come'on

    This is a problem for the Guru's com'on..! forever greatful.. i need a long... ooh eer!

  9. #9
    Guest
    1st off, the answer to your question.

    Code for C++ DLL.
    Code:
    #include "windows.h"
    extern "C" __declspec(dllexport) int _stdcall CppFunc(int num)
    {
    	return num;
    }
    Code for VB.
    Code:
    Private Declare Function CppFunction Lib "C:\MyPath\CppDll.dll" Alias "_CppFunc@4" (ByVal num As Integer) As Integer
    
    Private Sub Command1_Click()
        Print CppFunction(34)
        'returns 34 (or whatever you pass through)
    End Sub
    Secondly, when you ask a question give people time to answer it. You posted twice within 4 hours. Sometimes it takes days to get a response.

  10. #10
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    exellent

    Now then.. what about this long VB 4 is 32 bit why cant i send a long to c++ and return it back?

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