I think this time I get it right. The problem is your calling conventions, you use __cdecl in the
dll but when you call InitPlugin() you use FARPROCs (__stdcall). At some level things get messed up,
stack coruption probably . This is a working version of SetPlugInMenu(), sorry for my first replay.
Laur
PLUGINS SetPlugInMenu(HWND hwnd)
{
PLUGINS P = malloc(sizeof(struct _Plugins));
P->num = 0;
P->path = NULL;
HMODULE hmod;
//FARPROC PLG_Init, PLG_Free;
typedef char *(__cdecl *f1) (char *, int);
typedef void (__cdecl *f2) (void);
f1 PLG_Init;
f2 PLG_Free;
char dir[MAX_PATH], search[MAX_PATH], plugname[MAX_PATH];
GetSearchPath(dir, search);
HMENU hm = GetMenu(hwnd);
HMENU hsm = CreateMenu();
MENUITEMINFO mii = { 0 };
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_TYPE | MIIM_SUBMENU | MIIM_DATA;
mii.fType = MFT_STRING;
mii.hSubMenu = hsm;
mii.dwTypeData = "Plugins";
mii.cch = strlen("Plugins");
InsertMenuItem(hm, 1, TRUE, &mii);
WIN32_FIND_DATA find_data;
BOOL goon = TRUE;
HANDLE hfind = FindFirstFile(search, &find_data);
while (hfind != INVALID_HANDLE_VALUE && goon)
{
strcpy_s(plugname, MAX_PATH, dir);
strcat_s(plugname, MAX_PATH, find_data.cFileName);
hmod = LoadLibrary(plugname);
if (hmod)
{
PLG_Init = (f1)GetProcAddress(hmod, "InitPlugin");
PLG_Free = (f2)GetProcAddress(hmod, "FreePlugin");
if (PLG_Init && PLG_Free)
{
char MenuItem[100];
PLG_Init(MenuItem, 100);
if (P->num < 10)
{
sprintf(MenuItem, "%s\tStrg-%d", MenuItem, P->num);
}
AppendMenu(hsm, MF_STRING, IDM_PLUGITEM + P->num++, MenuItem);
P->path = realloc(P->path, P->num * sizeof(char *));
P->path[P->num - 1] = malloc(strlen(plugname) + 1);
strcpy(P->path[P->num - 1], plugname);
}
FreeLibrary(hmod); // we load them later as needed!
}
goon = FindNextFile(hfind, &find_data);
}
SetMenu(hwnd, hm);
return P;
}