C++ Dll for Game Maker 7

This is a discussion on C++ Dll for Game Maker 7 within the C++ Programming forums, part of the General Programming Boards category; Hello all, I am fairly new to c++ programming, and completely new to this forum. I am having a problem. ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    2

    C++ Dll for Game Maker 7

    Hello all, I am fairly new to c++ programming, and completely new to this forum. I am having a problem. This dll is supposed to display a dialog box with the words the person specefies in Game Maker 7.
    Here is my file dllmain.cpp:
    Code:
    /* Replace "dll.h" with the name of your header */
    #include "dll.h"
    #include <windows.h>
    
    export const CHAR* Dialog(const CHAR* string1, const CHAR* string2)
    {
      MessageBox(0,string1,string2,MB_OK);
    }
    And here is my Game Maker scripts (I will try to explain as good as I can for people who don't use Game Maker 7)

    Script dialog_init:
    Code:
    global.Dialog = external_define("WindowsDialog.dll", "Dialog" ,dll_stdcall ,ty_real, 2, ty_string, ty_string);
    global.Dialog is a variable defining the external function "Dialog" from the dll "WindowsDialog.dll".
    dll_stdcall is the call type
    ty_real is the resource type
    2 is the number of arguments (caption and text)
    ty_string and ty_string are the strings for caption and text

    And here is the script show_dialog:
    Code:
    external_call(global.Dialog, argument0, argument1);
    argument0 is the first parameter the user types when he calls the script for the caoption
    so is argument1 for the text

    And finally the code used to call it:

    Code:
    dialog_init();
    show_dialog('Caption','Text');
    Initializes the dll
    Shows the dialog with the caption 'Caption' and the text 'Text'.

    Here is where the problem comes in. It works perfectly, and the gives me an error and I have to abort. Can anyone help me?
    Last edited by Hockeyflyers; 07-11-2007 at 08:26 AM.

  2. #2
    Registered User
    Join Date
    Nov 2006
    Posts
    65
    I've done this before (University Project) using cdecl.

    In the cpp_header:
    Code:
    /* auto generated junk by Visual Studio. Preferably, use your own include guard (instead
               of #pragma once ) */
    
    #pragma once
    
    #ifndef WINVER                // Allow use of features specific to Windows XP or later.
    #define WINVER 0x0501         // Change this to the appropriate value to target other versions of Windows.
    #endif
    
    #ifndef _WIN32_WINNT          // Allow use of features specific to Windows XP or later.                   
    #define _WIN32_WINNT 0x0501   // Change this to the appropriate value to target other versions of Windows.
    #endif						
    
    #ifndef _WIN32_WINDOWS        // Allow use of features specific to Windows 98 or later.
    #define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
    #endif
    
    #ifndef _WIN32_IE             // Allow use of features specific to IE 6.0 or later.
    #define _WIN32_IE 0x0600      // Change this to the appropriate value to target other versions of IE.
    #endif
    
    #define WIN32_LEAN_AND_MEAN   // Exclude rarely-used stuff from Windows headers
    // Windows Header Files:
    #include <windows.h>
    
    
    /* The main part: */
    extern "C" __declspec(dllexport) double __cdecl My_Func(char *my_arg);
    In the cpp file.
    Code:
    #include "cpp_header.h"
    
    #ifdef _MANAGED
    #pragma managed(push, off)
    #endif
    
    BOOL APIENTRY DllMain( HMODULE hModule,
                           DWORD  ul_reason_for_call,
                           LPVOID lpReserved
    					 )
    {
    	if (ul_reason_for_call == DLL_PROCESS_ATTACH)
    	{
    		/* do initialization here, e.g std::srand((unsigned)time(0)); */
    	}
    	else if (ul_reason_for_call == DLL_PROCESS_DETACH)
    	{
                    /* clean up here */
    	}
        return TRUE;
    }
    
    #ifdef _MANAGED
    #pragma managed(pop)
    #endif
    
    __declspec(dllexport) double __cdecl My_Func(char *my_arg) {
      /* ......... your cpp code here ............. */
      return ret;
    }
    Now, in game maker, you should preferably have a presistant object and call your external_defines there:
    Code:
        global.My_Func = external_define("MyDll.dll","My_Func",dll_cdecl,ty_real,1,ty_string);
    At the end of the game, call external_free("MyDll.dll");
    Last edited by coder8137; 07-12-2007 at 01:04 AM.

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    2
    Great thanks! It works!

    But I have one question.
    How would I be able to get the Game window to be the window parent?

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    65
    But I have one question.
    How would I be able to get the Game window to be the window parent?
    From Game Maker, you can get the window handle (for the main window) using window_handle(). You'll have to pass this to the DLL and then use the win API to set the parent of your new window. However, I don't normally use the Windows API, so I couldn't tell you what the function calls would look like; you can probably specify the parent when you create the window.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 07:11 AM
  2. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  3. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 12:34 PM
  4. .lib vs .h vs .dll
    By Shadow12345 in forum C++ Programming
    Replies: 13
    Last Post: 01-01-2003, 04:29 AM
  5. Passing parameters from VB to C++ through ActiveX DLL
    By torbjorn in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2002, 02:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21