Results 1 to 40 of 81

Thread: passing structure from VC DLL to VB through CALLBACK function

Threaded View

  1. #4

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Hi, Finally can manage to partially solve the passing structure from the DLL to my external program. But I still facing a problem and I have somethings which I not really clear about it and hope someone can explain a little bit more detail to me

    Here is my VC DLL Definition file:
    ; MyDLL.def : Declares the module parameters.

    LIBRARY "MyDLL.dll"

    EXPORTS
    MyMultiply @1 ;PRIVATE
    MyLTrim @2 ;PRIVATE MyRTrim @3 ;PRIVATE
    MyCallback1 @4 ;PRIVATE
    MyCallback2a @5 ;PRIVATE
    MyCallback2b @6 ;PRIVATE
    MyCallback2_SetProcAddress @7 ;PRIVATE
    MyTimerProc_Start @8 ;PRIVATE
    MyTimerProc_Stop @9 ;PRIVATE
    Q1. Does the @x important?
    -----Where x equal to total memory size require.
    -----As from the MSDN, I know this is use to indicate the total memory in byte require for that particular function (for both input arguement and output result).

    Q2. How about the PRIVATE keyword behind it?
    Incident 1
    With the PRIVATE at the end of the EXPORT list.
    E.g.
    MyCallback1 @4 PRIVATE
    -----When I compile the DLL and test with the normal WIN32 VC application. I hit the Unresolved External link error (LINK 2001).
    -----But there is no error in VB test program. Why?

    Incident 2
    Without the PRIVATE at the end of the EXPORT list.
    E.g.
    MyCallback1 @4
    -----There was no link error in VC test program.
    -----But When ran the VB test program, will hit the following error. ('DLL entry poiint for MyCallback1 not found'). Why?

    Q3. Does the __cdecl equal CALLBACK keyword?
    E.g.
    typedef void (__cdecl* ExCallback1)(long);
    and
    typedef void (CALLBACK* ExTimerProc)(long);

    Q4. Does CALLBACK function must return a value?
    E.g.
    If define as:
    __declspec(dllexport) void __stdcall MyCallback2(long lParam1, char *strParam2)
    ----The lParam1 and strParam2 will not equal to the pass in value.
    If define as:
    __declspec(dllexport) long __stdcall MyCallback2(long lParam1, char *strParam2)
    -----The lParam1 and strParam2 will equal to the pass in value.

    Q5. Why I hit 'Unhandle error' in my VB callback function upon I execute any standard window API function like 'GetTickCount'?

    Q6. Why I can't use 'On Error' in my own define callback function?
    E.g.

    VB Code:
    1. Sub Callback1 (Byval lParam1 As Long, Byval lParam2 As long)
    2. On Error Goto Errhandle:
    3.     ' All my code is here...
    4.  
    5.     Exit Sub
    6. ErrHandle:
    7.  
    8. End Sub

    Q7. I manage to return the structure to my VB main program.
    Let said, my structure is having 2 parameters:
    E.g.

    VB Code:
    1. Public Type CB2
    2.         ID As Long
    3.         Name As String * 255
    4.     Type
    5.     Public pv1 As CB2

    When the callback function is fire, I received this structure and all the data inside this function is correct except the String parameter. Where I get the question mark and not my data.
    VB Code:
    1. pv1.Name = ????

    But when I check with my VC DLL (1 step before calling this callback function and all the data inside this structure is perfectly assign/copy). What cause the problem? Do I need some special syntax to handle this string passing?

    Again, I hit 'ESP' error in VC test program too.

    I've enclosed the saource for the DLL (VC) and two (2) test program in both VC and VB.

    Q8. Whats the different between the 'WINAPI' and __declspec(dllexport) void __stdcall?

    I really appreatiate someone can guide me to a correct direction on creating a cross language DLL or a perfect driver

    The sample code is available at this URL... MyDLL.zip

    regards,
    Chris
    Last edited by Chris; Sep 9th, 2001 at 10:51 PM.

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