Old 25th October 2011, 10:43   #1
derbasti1896
Junior Member
 
Join Date: Apr 2011
Posts: 6
Winamp Plugin: Problem with calling function

Hallo,

i have got a problem with my plugin. It's a little GUI with just some buttons and those stuff.
I want Winamp to do some standard operations by clicking the button. Maybe "Play".

I have got the GUI-program and the DLL but the function does not work.

Winamp Plugin (DLL):

#include <windows.h>
#include "dll.h"
#include "wa_ipc.h"

// these are callback functions/events which will be called by Winamp
int init(void);
void config(void);
void quit(void);
extern "C" __declspec(dllexport)void test(void);

// this structure contains plugin information, version, name...
// GPPHDR_VER is the version of the winampGeneralPurposePlugin (GPP) structure
winampGeneralPurposePlugin plugin = {
GPPHDR_VER, // version of the plugin, defined in "gen_myplugin.h"
PLUGIN_NAME, // name/title of the plugin, defined in "gen_myplugin.h"
init, // function name which will be executed on init event
config, // function name which will be executed on config event
quit, // function name which will be executed on quit event
0, // handle to Winamp main window, loaded by winamp when this dll is loaded
0 // hinstance to this dll, loaded by winamp when this dll is loaded
};


// event functions follow

int init() {

MessageBox(plugin.hwndParent, "Init event triggered for gen_myplugin. Plugin installed successfully!", "", MB_OK);
return 0;
}

void config()
{
MessageBox(plugin.hwndParent, "Config event triggered for gen_myplugin.", "", MB_OK);
}

void quit()
{
MessageBox(0, "Quit event triggered for gen_myplugin.", "", MB_OK);
}

void test()
{

//MessageBox(plugin.hwndParent, "Hat geholfen", "", MB_OK);

enqueueFileWithMetaStruct eFWMS = {0};
eFWMS.filename="c:\\02 - Subway to Sally - Veitstanz.mp3";
eFWMS.title = "Subway to Sally - Veitstanz";
eFWMS.length = 300;
SendMessage(plugin.hwndParent,WM_WA_IPC,(WPARAM)&eFWMS,IPC_ENQUEUEFILE);
}


// This is an export function called by winamp which returns this plugin info.
// We wrap the code in 'extern "C"' to ensure the export isn't mangled if used in a CPP file.
extern "C" __declspec(dllexport) winampGeneralPurposePlugin * winampGetGeneralPurposePlugin() {
return &plugin;
}




GUI:

#include <iostream>
#include <windows.h>
#include <wa_ipc.h>

using namespace std;
typedef void (*funktion1)(void);


int main (int argc, char *argv[])
{


HINSTANCE hdll = LoadLibrary("c:\\Program Files (x86)\\Winamp\\Plugins\\gen_testplugin.dll");

if (hdll != NULL)
{
funktion1 test = (funktion1)GetProcAddress(hdll,"test");

if (!test)
{
// handle the error
FreeLibrary(hdll);
cout << "Proc Address Error" << endl;
Sleep (10000);
}
else
{
// call the function
test();
cout << "Erfolgreich" << endl;
Sleep (10000);
}
}
else
{
cout << "Load Library Error" << endl;
Sleep (10000);
}

}


The function test does not work but i dont know why. Can anybode help me?

IDE: wxDev-C++

Thank you very much...
derbasti1896 is offline   Reply With Quote
Old 25th October 2011, 13:26   #2
DrO
 
Join Date: Sep 2003
Posts: 27,873
it's because you're external gui app is loading a new instance of the plug-in dll which doesn't have any of the Winamp related values like 'plugin.hwndParent' and so it will never work.

i guess you have your reasons for doing it as a gui exe and a plug-in but you can do ui stuff in the plug-in. also if you're wanting to trigger an action, you could look for the Winamp instance and then find the hinstance of the plug-in as obtained by GetModuleHandle(..) before then calling the test(..) function. or register a custom message which the plug-in can detect and respond to -this can be done with IPC_REGISTER_WINAMP_IPCMESSAGE and sub-classing the main Winamp window.

-daz
DrO is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > Winamp Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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