Old 01-02-2020, 04:46 AM   #1
Dim-Z
Human being with feelings
 
Join Date: Jan 2020
Posts: 2
Default Bug when plugin start

Hello.
I am try to write my reaper plugin.
If Reaper start with my reaper_test.dll this crash...
Please help me, and show how to write normal plugin.

my code:
Code:
#include <stdio.h>
#include <stdbool.h>
#include <windows.h>

#define REAPER_PLUGIN_DLL_EXPORT __declspec(dllexport)
#define REAPER_PLUGIN_HINSTANCE HINSTANCE
#define REAPERAPI_DEF extern

#define REAPER_PLUGIN_VERSION 0x20E
#define IMPAPI(x) if (!errcnt && !((*(void **)&(x)) = (void *)rec->GetFunc(#x))) errcnt++;

typedef struct reaper_plugin_info_t
{
int caller_version; // REAPER_PLUGIN_VERSION

HWND hwnd_main;

// this is the API that plug-ins register most things, be it keyboard shortcuts, project importers, etc.
// typically you register things on load of the DLL, for example:

// static pcmsink_register_t myreg={ ... };
// rec->Register("pcmsink",&myreg);

// then on plug-in unload (or if you wish to remove it for some reason), you should do:
// rec->Register("-pcmsink",&myreg);
// the "-" prefix is supported for most registration types.
int (*Register)(const char *name, void *infostruct); // returns 1 if registered successfully

// get a generic API function, there many of these defined.
void * (*GetFunc)(const char *name); // returns 0 if function not found
} reaper_plugin_info_t;

bool (*APIExists)(const char* function_name);
void (*APITest)();
void (*ShowConsoleMsg)(const char* msg);
int (*ShowMessageBox)(const char* msg, const char* title, int type);

REAPERAPI_DEF REAPER_PLUGIN_DLL_EXPORT int ReaperPluginEntry(REAPER_PLUGIN_HINSTANCE hInstance, reaper_plugin_info_t *rec)
{
if (rec != NULL)
{
int errcnt = 0;

IMPAPI("ShowMessageBox");

ShowMessageBox("Happy new year", "with", 0);
return 1;
}
else
{
ShowMessageBox("Quit plugin", "Good bye", 0);
return 0;
}
}
Dim-Z is offline   Reply With Quote
Old 01-02-2020, 05:09 AM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
Default

Line 44 is writing into read-only memory (attempting to write the address of the ShowMessageBox function into the "ShowMessageBox" string literal):

Code:
*(void **)&"ShowMessageBox" = (void *)rec->GetFunc("ShowMessageBox")
...instead of writing into the ShowMessageBox function pointer. Remove the quotes at line 44. Also REAPERAPI_DEF should be extern "C".

You can also refer to https://gist.github.com/cfillion/f32...63abb1eda41400 for an example of a basic extension plugin.

Last edited by cfillion; 01-02-2020 at 05:18 AM.
cfillion is offline   Reply With Quote
Old 01-02-2020, 06:24 AM   #3
Dim-Z
Human being with feelings
 
Join Date: Jan 2020
Posts: 2
Default

Hello Christian!
My big thanks for you answer!
I learned reaper plugin creation in your codes.

I only try this.
Dim-Z is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:06 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.