Dumb question ??

  • 19 years ago


    Hi


    I was looking for help on how to pass a window handle from VB to a C++ dll and use it in an API call.


    Example of passing a long and Multiplying by 2 :-


    (VB code)
    Private Declare Function TimesTwo Lib "MyTestDll.dll" (ByVal FirstParam As Long) As Long


    Private Sub Form_Load()
       Debug.Print TimesTwo(2)
    End Sub


    (DLL code)

    define MYTESTDLLEXIM extern "C" __declspec(dllexport)


    include "main.h"



    MYTESTDLLEXIM long _stdcall TimesTwo( long FirstParam)
    {
       return ( FirstParam * 2);
    }


    Example end


    This shows that passing a few variables to a dll to deal with some complicated/time consuming maths is actually quite easy. The above example returns 4.


    Now back to my original question as I side tracked a little there to try to clarify my question. Look at this incomplete/incorrect example and see if you can understand what I want to achieve.


    (VB code)
    Private Declare Function FlashForm Lib "MyTestDll.dll" (ByVal hwnd As Long)


    Private Sub Form_Load()
      Flashform(Me.hwnd)
    End Sub


    (DLL code)

    define MYTESTDLLEXIM extern "C" __declspec(dllexport)


    include "main.h"


    include <window.h>



    MYTESTDLLEXIM long stdcall FlashForm( long hwndPassed)
    {
                  // This is the bit I'm stuck on
                  FlashWindow(handle of form1 goes here, 1)   // 1 = Invert
       return (0);
    }


    Example end


    I want to pass form1 window handle and use the FlashWindow API in the dll to flash the form.
    Thats it..  Can I say, before I get flamed, that I just want to get to grips with C++ instruction set first so I can augment my VB with dlls and I dont want to get swamped with learning Visual C++ totally at this point. I have asked in various IRC channels and basically was told to @#$#@ and learn C++. You dont need to be a mechanic to drive a car do you ?? and I only do this for fun


    Ok.. hope this isnt too lame a question


    Thanks

  • 19 years ago

    I hardly know any C++, but can't you do


    Code:
    MYTESTDLLEXIM long stdcall FlashForm( long hwndPassed)
    {
                  // This is the bit I'm stuck on
                  FlashWindow(hwnd_Passed, 1)   // 1 = Invert
       return (0);
    }


    ???

  • 19 years ago

    First, thanks for your reply


    Well your suggestion is exactly what I tried before asking here.
    The problem is that VB passes the hwnd as long and C++ uses a different data type for handles.
    So when I compile it returns the error :-


    "Cannot cast long to _Struct hwnd"


    So other than using the FindWindow API which kinda defeats the object when VB is supposedly passing a handle, I'm still stuck....


    Anyway, at least you had a good go


Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Computer Science is no more about computers than astronomy is about telescopes.” - E. W. Dijkstra