Compile a DLL in C/C++, then call it from another program

前端 未结 5 1169
死守一世寂寞
死守一世寂寞 2020-11-27 09:12

I want to make a simple, simple DLL which exports one or two functions, then try to call it from another program... Everywhere I\'ve looked so far, is for complicated matter

5条回答
  •  臣服心动
    2020-11-27 10:06

    For VB6:

    You need to declare your C functions as __stdcall, otherwise you get "invalid calling convention" type errors. About other your questions:

    can I take arguments by pointer/reference from the VB front-end?

    Yes, use ByRef/ByVal modifiers.

    Can the DLL call a theoretical function in the front-end?

    Yes, use AddressOf statement. You need to pass function pointer to dll before.

    Or have a function take a "function pointer" (I don't even know if that's possible) from VB and call it?)

    Yes, use AddressOf statement.

    update (more questions appeared :)):

    to load it into VB, do I just do the usual method (what I would do to load winsock.ocx or some other runtime, but find my DLL instead) or do I put an API call into a module?

    You need to decaler API function in VB6 code, like next:

    Private Declare Function SHGetSpecialFolderLocation Lib "shell32" _
       (ByVal hwndOwner As Long, _
        ByVal nFolder As Long, _
        ByRef pidl As Long) As Long
    

提交回复
热议问题