Old 26th February 2007, 11:01   #1
5ven
Junior Member
 
Join Date: Feb 2007
Posts: 4
Newbie and first general plugin

Hi,

I am trying make a general plugin, just to test some concepts and things. I've got the SDK installed, also Visual C++ Express and Dev C++, too. I downloaded the empty general plugin- and compiled it successfully.

Now I have been trying to accomplish something more advanced than a MessageBox - I would like to have a DialogBox instead that would appear on clicking the "Configure selected plugin". I've read through some GPL plugins' code and checked the SDK's tray plugin. With the help of these I have got to the point where I got no compilation errors - but no DialogBox, either.

Here is the code that I have written:

--------------- gen_test.h---------------------------
#ifndef gen_test_h
#define gen_test_h
#include <windows.h>
#include "resource.h"

typedef struct {
int version;
char *description;
int (*init)();
void (*config)();
void (*quit)();
HWND hwndParent;
HINSTANCE hDllInstance;
} winampGeneralPurposePlugin;

BOOL CALLBACK ConfigProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam);

#define GPPHDR_VER 0x10

extern "C" winampGeneralPurposePlugin *gen_plugins[256];
typedef winampGeneralPurposePlugin * (*winampGeneralPurposePluginGetter)();
#endif
---------------------------------------------

-------------------gen_test.cpp--------------
#include "gen_test.h"
#define PLUGINNAME "Test v0.2"
#define PLUGIN_DESC "Test plugin"


BOOL APIENTRY _DllMainCRTStartup(HANDLE hMod, DWORD r, void *empty){
return 1;
}

HWND hConfigDialog = NULL;
HWND hAddDialog = NULL;

extern "C" winampGeneralPurposePlugin plugin;


int init() {return 0;}

void config() {
DialogBox(plugin.hDllInstance,MAKEINTRESOURCE(IDD_CONFIG),NULL,ConfigProc);
}


void quit() {}

winampGeneralPurposePlugin plugin = {
GPPHDR_VER,
PLUGINNAME,
init,
config,
quit,
0
};

BOOL CALLBACK ConfigProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
switch (message) {
case WM_INITDIALOG : {
hConfigDialog = hwnd;
// SetWindowText(hwndDlg,PLUGIN_DESC);
SetWindowText( hwnd, "Test" );
//SetDlgItemText(hwndDlg,IDC_EDIT1,"WinApi");
ShowWindow(hwnd,SW_SHOW);
}
return TRUE;
case WM_COMMAND: {
break;
}
}
return FALSE;
}

extern "C" __declspec( dllexport ) winampGeneralPurposePlugin * winampGetGeneralPurposePlugin(){
return &plugin;
}
--------------------------------------------------

---------------------resource.h-------------------
#define IDD_CONFIG 101
#define IDC_EDIT1 102
--------------------------------------------------

I am suspecting that something might be missing at ConfigProc.
5ven is offline   Reply With Quote
Old 26th February 2007, 13:19   #2
DrO
 
Join Date: Sep 2003
Posts: 27,873
i can't test it here though it looks correct (especially since you've got a ShowWindow(..) in there. Best thing to do is check the return value from the DialogBox call and see what the error reported is (GetLastError(..))

-daz
DrO is offline   Reply With Quote
Old 26th February 2007, 15:27   #3
5ven
Junior Member
 
Join Date: Feb 2007
Posts: 4
Thanks for the tip! I Googled around a bit and found this article: http://www.relisoft.com/win32/windlg.html

Then modified the config() (and added ErrorString()) and now the code looks like this:

char* ErrorString(DWORD err,char* error){
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, error, 255, NULL);
return error;
}

void config() {
HWND hDialog = NULL;
hDialog = CreateDialog
(
plugin.hDllInstance,
MAKEINTRESOURCE (IDD_CONFIG),
plugin.hwndParent,
ConfigProc
);
if(!hDialog){
char error[255];
MessageBox(NULL, ErrorString(GetLastError(),error), "Error!", MB_OK | MB_ICONEXCLAMATION);
LocalFree(error);
}
}

Then I got the error message - it was "The specified image file did not contain a resource section". The error message at the MSDN refrence: ERROR_RESOURCE_DATA_NOT_FOUND 1812

Last edited by 5ven; 26th February 2007 at 16:20.
5ven is offline   Reply With Quote
Old 26th February 2007, 16:59   #4
5ven
Junior Member
 
Join Date: Feb 2007
Posts: 4
slowly I am moving forward I found out that the error means that the resources file was not properly set up: h**p://cboard.cprogramming.com/archive/index.php/t-66001.html Now I am trying with dev-cpp because it seems easier to deal with - less options.
5ven is offline   Reply With Quote
Old 26th February 2007, 17:52   #5
5ven
Junior Member
 
Join Date: Feb 2007
Posts: 4
Yeah! Happy one here! The missing resources files were the reason. I appended resources.rc and resources.h to the project at dev-cpp. And then after some fiddling the compilation worked. Here are the contents of the files:

---------------------resources.rc-------------------------
#include "resources.h"

IDD_CONFIG DIALOG 260, 200, 188, 95
CAPTION "Test"
FONT 8, "Courier New"
BEGIN
END
----------------------------------------------------------

--------------------resources.h---------------------------
#define IDD_CONFIG 1
----------------------------------------------------------

and then also added #include "resources.h" to gen_test.h
5ven 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