Page 2 of 2 FirstFirst 12
Results 26 to 27 of 27

Thread: C++ Plugins!

  1. #26
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,691
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Well, today I made a C Plugin for SCAR with a friend, during a college.
    It only works on the SCAR Portable edition, don't ask me why.
    It should compile with the GCC Compiler, and the Microsoft Compiler.
    I didn't add a DLLMain, since that seems redundant.
    It might be the reason it isn't working on the SCAR Normal editions, or it is just generally a bug in the normal SCAR Editions, and accidentally fixed in the Portable Editions. (It doesn't work on 2.03, either)


    Code:
    #define EXPORT_FUNCTIONS
    #include "main.h"
    #include <windows.h>
    
    DLLCALL unsigned int GetFunctionInfo(unsigned int x,void** ppfunc,char** szlppString)
    {
    	switch(x)
    	{
    	case 0:
    		strcpy(*szlppString,"procedure hello();");
    		*ppfunc = (void*)hello;
    		break;
    	default:
    		return -1;
    	}
    	return x;
    }
    
    DLLCALL unsigned int GetFunctionCount(void)
    {
    	return 1;
    }
    
    void hello()
    {
        MessageBox(NULL, "Testing 1 2 3", "DLL", MB_OK);
    }
    and the header(main.h) :

    Code:
    #ifdef EXPORT_FUNCTIONS
    #define DLLCALL __declspec(dllexport)
    #else
    #define DLLCALL __declspec(dllimport)
    #endif
    
    DLLCALL unsigned int GetFunctionInfo(unsigned int x,void** ppfunc,char** szlppString);
    DLLCALL unsigned int GetFunctionCount(void);
    void hello();
    Will update on this later... I guess.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  2. #27
    Join Date
    Jan 2012
    Location
    Vilnius, Lithuania
    Posts
    33
    Mentioned
    1 Post(s)
    Quoted
    12 Post(s)

    Default

    Bumping this old thread...

    So I'm using this code:
    Code:
    #include <windows.h>
    #define Export _declspec(dllexport)
    #define DelphiExport extern "C" Export
    
    HINSTANCE inst;
    
    Export BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID checks) {
        switch(reason) {
            case DLL_PROCESS_ATTACH:
                //Do you're init here, but don't change anything else (besides cleanup)
                inst = instance;
            case DLL_THREAD_ATTACH:
                return true;
            case DLL_PROCESS_DETACH:
                //Do you're cleanup here, but don't change anything else (besides init)
                FreeLibrary(inst);
            case DLL_THREAD_DETACH:
                return true;
        }
        return false;
    }
    
    //Add in your functions
    
    void Test(void) {
        //Shows a message box.
        MessageBox(NULL, "Testing 1 2 3", "DLL", MB_OK);
    }
    
    //Export name changed in def file
    DelphiExport int __stdcall GetFunctionCount(void) {
        return 1; //Change depending on number to export
    }
    
    //Export name changed in def file
    DelphiExport int __stdcall GetFunctionInfo(int x, void** address, char** def) {
        switch (x) {
            case 0:
                *address = (void*)Test;
                strcpy(*def,"procedure DllTest;"); //Have to strcpy, how you want it to be called
                return x;
        }
        return -1;
    }
    Compiled with CodeBlocks.

    Simba script:
    Code:
    program new;
    
    {$loadlib test2}
    
    begin
      DllTest;
    end.
    However I get error that DllTest is undefined.
    It also sometimes give "Your DLL test2 has not been found. Exception in Script: Unknown compiler directives at 4:3" errors.

    Few things wasn't clear for me:
    1. .def file has to be generated by compile or should I create it manually? And if my dll is test2.dll so this file should be test2.def?
    2. How do I enable debugging to know what functions were exported?

    Thanks.

    EDIT: Nvm, fixed... I was unable to make Code::Blocks include .def file into dll so I used MinGW.
    Last edited by chemicstry; 01-29-2012 at 05:05 PM.

Page 2 of 2 FirstFirst 12

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 12-20-2008, 06:19 PM
  2. plugins..help?
    By n0n4m311 in forum OSR Help
    Replies: 3
    Last Post: 10-04-2008, 03:59 PM
  3. Replies: 2
    Last Post: 01-18-2008, 10:20 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
  •