-1

WinApi を使用して Winamp プラグインを作成しました。

Winamp を閉じると、GUI (Winamp のウィンドウと私のプラグインのウィンドウの両方) が消えます... しかし、Windows のタスク マネージャーにまだ Winamp.exe が表示されます。

Winamp のプラグイン ディレクトリから gen_mood.dll (私のプラグイン ファイル) を削除した後、すべて問題ありません。Winamp を正しく閉じることができます。

これが私の最小限のコードです。誰かが何が悪いのか教えてもらえますか? Visual Studio 2013 と Winamp 5.666 を使用しています。

gen_mood.cpp:

#include "stdafx.h"
#include <windows.h>
#include "gen_mood.h"

// these are callback functions/events which will be called by Winamp 
int init(void); void config(void); void quit(void); void makeSetlist();
using namespace std;


// 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_mood.h"
PLUGIN_NAME, // name/title of the plugin, defined in "gen_mood.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
MSG Komunikat;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
HWND hwnd; 
int init() {

    HFONT hNormalFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
    LPCWSTR ClassName = L"Class name";
    WNDCLASSEX wc;

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_VREDRAW;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = plugin.hDllInstance;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = ClassName;
    wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

    RegisterClassEx(&wc);   
    hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, ClassName, L"Name", WS_OVERLAPPED, 100, 100, 100, 100, plugin.hwndParent, NULL, plugin.hDllInstance, NULL);
    ShowWindow(hwnd, SW_SHOW);
    UpdateWindow(hwnd);

    while (GetMessage(&Komunikat, NULL, 0, 0))
    {
        TranslateMessage(&Komunikat);
        DispatchMessage(&Komunikat);
    }

    return 0;
}

void config() {}
void quit() {}

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

}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
    case WM_CLOSE:
        DestroyWindow(hwnd);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

gen_mood.h:

#ifndef gen_mood_h
#define gen_mood_h
#include <windows.h>

// plugin version (don't touch this)
#define GPPHDR_VER 0x10

// plugin name/title (change this to something you like)
#define PLUGIN_NAME "Mood"


// main structure with plugin information, version, name... 
typedef struct {

    int version;                   // version of the plugin structure
    char *description;             // name/title of the plugin 
    int(*init)();                 // function which will be executed on init event
    void(*config)();              // function which will be executed on config event
    void(*quit)();                // function which will be executed on quit event
    HWND hwndParent;               // hwnd of the Winamp client main window (stored by Winamp when dll is loaded)
    HINSTANCE hDllInstance;        // hinstance of this plugin DLL. (stored by Winamp when dll is loaded) 

} winampGeneralPurposePlugin;


#endif //gen_mood_h
4

1 に答える 1

0

私は解決策を見つけました。に問題がありました

while (GetMessage(&Komunikat, NULL, 0, 0))
{
    TranslateMessage(&Komunikat);
    DispatchMessage(&Komunikat);
}

Winamp のメイン ウィンドウはメッセージ ポンプを実行しているため、自分でメッセージ ポンプを作成しても意味がありませんでした。この行を削除したところ、すべて正常に動作するようになりました。

于 2014-09-10T14:12:58.993 に答える