Results 1 to 12 of 12

Thread: Connecting to C++ again

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Yes.

    I have absolutley no Idea where to go from there, I learnt C++ from the complete Idiots guide to C++ and I only know how to do console mode apps, but I know enough about the API to do everything I need in the functions, I've tested the functions from a bit of a consolemode front end and they work (as far as I can tell, I didn't bother putting the graphics out to the screen)

    I need it as a dll as I pass out pointers an use callback functions can I pass out pointers in a staticly linked app (obviously I can but can I get at the memory).


  2. #2
    Lively Member
    Join Date
    Jan 1999
    Location
    Rochester NY, USA
    Posts
    93
    if you're using VC then you'd use the wizard to make a dll.. in order to get at the functions in your dll, you have to export them. Here's some info on that...

    MFC DLL -
    http://msdn.microsoft.com/library/de...an_mfc_dll.htm

    C DLL -
    http://msdn.microsoft.com/library/of...ce97/SF7E6.htm

    You'd refrence them in VB the same way you refrence any other DLL call. like...


    <from VB5 help>
    Declare Sub MessageBeep Lib "User32" (ByVal N As Long)

    you're saying that MessageBeep is in lib user32 and it's expecting a long.

    Hope that helps..





  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Ok I'm still having trouble, I start up the appwizard and select win32dll, and use a simple DLL, I type my function in like the website said so It looks like this
    Code:
    _declspec(dllexport) long  _cdecl myfunc(short factor1,short factor2)
    {
    	return (long)(factor1 * factor2);
    }
    into the main cpp file and batchbuild so I get a release version.

    I declare it in VB and it can't find the file unless I give it the full file extension, when I do this it says that it can't find DLL entry point myfunc.

    What do I do? This is really frustrating.

  4. #4
    Lively Member
    Join Date
    Jan 1999
    Location
    Rochester NY, USA
    Posts
    93
    how did you declare it in your vb app?

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    I'm declaring it as I would an API
    Code:
    Private Declare Function myfunc Lib "C:\TestDll\Release\TestDll" (factor1 As Integer, Factor2 As Integer) As Long
    I've tried loads of other ways of doing it (C++ side) as well, every source in MSDN does it differently and they all give me the same error.

  6. #6
    Lively Member
    Join Date
    Jan 1999
    Location
    Rochester NY, USA
    Posts
    93
    I think you're missing the actual "EXPORT" part. It does get a little confusing. Here's another article that may help.. though it's more in-depth and may confuse you even more..

    http://msdn.microsoft.com/library/de...plications.htm

    let me know how you make out.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Thanks, I think I've seen that but I'll have another look, I think MSDN is just designed to confuse people.

  8. #8
    Guest
    It maybe a type but you are missing an underscore on the __declspec

    _declspec(dllexport) long _cdecl myfunc(short factor1,short factor2)
    {
    return (long)(factor1 * factor2);
    }

    then depending on what you do inside your function you may have to do:
    extern "C"
    {
    __declspec(...)...
    }

    and did you do the BOOL WINAPI DllMain?




  9. #9
    Guest
    /*
    OK i should have read all of the messages, here is what you do, paste this into a .cpp and compile:
    */

    #include<iostream.h>

    /*
    this is where you enter the dll,
    you must have it, and it won't work without it
    that's where you get the error message
    */

    BOOL WINAPI DllMain(HANDLE HModule, DWORRD ul_reason_for_call, LPVOID lpReserved)
    {
    switch(ul_reson_for_call)
    {
    case DLL_PROCESS_ATTACH:
    break;
    case DLL_PRECESS_DETACH:
    break;
    }
    return(TRUE);

    /*depending on functions you use*/
    extern "C"
    {
    extern __declspec( dllexport) long myFunctionName(myParameters);
    }

    long myFunctionName(myParameters)
    {
    return(10);
    }

    [Edited by Faust on 05-01-2000 at 04:08 PM]

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    /*depending on functions you use*/
    extern "C"
    {
    extern __declspec( dllexport) long myFunctionName(myParameters);
    }
    I missed out that bit, I wish MSDN was good, it should have made it clearer.

    I'm assuming this is a bit like the way you declare functions in classes, and that you can overload them and the like, I makes much more sense now thanks.
    If it wasn't for this sentence I wouldn't have a signature at all.

  11. #11
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    Sam,

    MSDN Article Q194609 may be of some help to you. It's available at http://msdn.microsoft.com/default.asp (use search on Q194609). Hope it helps.

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    OK, I've just about got the hang of it, Thanks a lot for your help.

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