Help with ExportFunctions and GetPluginExports

Started by jokeritoval, Mar 24, 2017, 09:37 AM

Previous topic - Next topic

jokeritoval

Please give me a some examples how to use this functions in VCMP SDK

ExportFunctions
GetPluginExports

I am see how it works in Squirrel plugin sources
but dont understand how it works

Please give some SIMPLE examples how to use it

I am try to use

mainplugin.c
int GetSrv()
{
return 900;
}
typedef struct
{
int structSize;

int (*GetSrv)(void); // pointer to funct
} ExportFunc;

extern EXPORT unsigned int VcmpPluginInit( PluginFuncs* pluginFuncs, PluginCallbacks* pluginCalls, PluginInfo* pluginInfo )
{
int ret;
ExportFunc *fc = (ExportFunc*)malloc(sizeof(ExportFunc));
fc->GetSrv = GetSrv;



    pluginInfo->apiMajorVersion = PLUGIN_API_MAJOR;
    pluginInfo->apiMinorVersion = PLUGIN_API_MINOR;

// give name plugin for other finding plugins
pluginInfo->pluginVersion = 0x100;
strcpy(pluginInfo->name, "main_plugin");



// Export them
pluginFuncs->ExportFunctions( pluginInfo->pluginId, (void **)&fc, sizeof(ExportFunc) );
}

and

additional_plugin.c
typedef struct
{
int structSize;

int (*GetSrv)(void); // указатель на функцию
} ExportFunc;

void OnSquirrelScriptLoad()
{
int err;

unsigned int size;
int sqId = functions->FindPlugin("main_plugin");
const void **sqExports = functions->GetPluginExports(sqId, &size);

// We do!
if (sqExports != NULL && size > 0)
{

ExportFunc *sqFuncs = (ExportFunc *)(sqExports);

if( sqFuncs )
{
int tea = sqFuncs->GetSrv();
printf("get size = %d\n", tea );
}
}
else {
printf("Failed to attach to pawn_plugin\n");
}
}

in console i see "get size = " and get Fatal Error

Please give me some SIMPLE example how to use ExportFunctions and GetPluginExports, NOT "solution" of my code

Thanks!