View Single Post
Old 16th January 2017, 13:34   #2
chinagreenelvis
Junior Member
 
Join Date: Nov 2009
Posts: 35
Well, I somehow managed to figure it out. In case any other newbs are wondering, your newly created gen_myplugin.cpp should look exactly like this (assign the hotkey in Preferences and test it out to see the confirmation message):

code:

/*

Winamp generic plugin template code.
This code should be just the basics needed to get a plugin up and running.
You can then expand the code to build your own plugin.

Updated details compiled June 2009 by culix, based on the excellent code examples
and advice of forum members Kaboon, kichik, baafie, burek021, and bananskib.
Thanks for the help everyone!

*/

#include "stdafx.h"
#include <windows.h>
#include "gen_myplugin.h"
#include "wa_ipc.h"
#include <stdio.h>

// these are callback functions/events which will be called by Winamp
int init(void);
void config(void);
void quit(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
};

// hotkeys
WNDPROC WinampProc;

typedef struct {
char *name; // this is the name that will appear in the Global Hotkeys preferences panel
DWORD flags; // one or more HKF_* flags from above
UINT uMsg; // message that will be sent to winamp's main window (must always be !=NULL)
WPARAM wParam; // wParam that will be sent to winamp's main window
LPARAM lParam; // lParam that will be sent to winamp's main window
char *id; // unique string to identify this command (the string is case insensitive)
HWND wnd; // set the HWND to send message (or 0 for the main winamp window)

int extended[6]; // for future extension - always set this to zero!
} genHotkeysAddStruct;

genHotkeysAddStruct test_key = { 0 }; // this will make the compiler zero the struct for you
// though you can do it manually if you want to as well
INT test_ipc = 0; // this will hold the uMsg value to look for in the assigned window proc

void AddGlobalHotkey(genHotkeysAddStruct *hotkey, char* name, char* id, int* ipc) {
UINT genhotkeys_add_ipc = 0;
hotkey->wnd = 0;
hotkey->flags = 0;
hotkey->name = name;
hotkey->id = id;
*ipc = hotkey->uMsg = SendMessage(plugin.hwndParent, WM_WA_IPC, (WPARAM)&hotkey->id, IPC_REGISTER_WINAMP_IPCMESSAGE);
genhotkeys_add_ipc = SendMessage(plugin.hwndParent, WM_WA_IPC, (WPARAM)&"GenHotkeysAdd", IPC_REGISTER_WINAMP_IPCMESSAGE);
PostMessage(plugin.hwndParent, WM_WA_IPC, (WPARAM)hotkey, genhotkeys_add_ipc);
}

LRESULT CALLBACK WinampWnd(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
int ret = 0;
// handles the hotkey for the option
if (uMsg == test_ipc) {
MessageBox(plugin.hwndParent, L"It appears to be working.", L"", MB_OK);
}
// do stuff before the winamp proc has been called

ret = CallWindowProc(WinampProc, hwnd, uMsg, wParam, lParam);
// do other stuff after the winamp proc has been called
// then return the value from CallWindowProc(..)
return ret;
}

// event functions follow

int init() {
//A basic messagebox that tells you the 'init' event has been triggered.
//If everything works you should see this message when you start Winamp once your plugin has been installed.
//You can change this later to do whatever you want (including nothing)

//MessageBox(plugin.hwndParent, L"Init event triggered for gen_myplugin. Plugin installed successfully!", L"", MB_OK);

AddGlobalHotkey(&test_key, "Playback: Test key", "Test_key", &test_ipc);
WinampProc = (WNDPROC)SetWindowLong(plugin.hwndParent, GWL_WNDPROC,
(LONG)WinampWnd);

return 0;
}

void config() {
//A basic messagebox that tells you the 'config' event has been triggered.
//You can change this later to do whatever you want (including nothing)

//MessageBox(plugin.hwndParent, L"Config event triggered for gen_myplugin.", L"", MB_OK);
}

void quit() {
//A basic messagebox that tells you the 'quit' event has been triggered.
//If everything works you should see this message when you quit Winamp once your plugin has been installed.
//You can change this later to do whatever you want (including nothing)

//MessageBox(0, L"Quit event triggered for gen_myplugin.", L"", MB_OK);
}

// 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;
}

chinagreenelvis is offline   Reply With Quote