代码是网上抄的,编译也过了,CPL也挎到了SYSTEM目录下了.可面板中没有程序呀!
代码如下;
#include "stdafx.h"
#include <afxdllx.h>
#include <CPL.h>
#include <winreg.h>#include "resource.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static AFX_EXTENSION_MODULE CplAppDLL = { NULL, NULL };HINSTANCE hinst = NULL;//控制面板接口函数CPlApplet
extern "C" int APIENTRY CPlApplet(HWND hwndCPL, UINT uMsg, LPARAM lParam1, LPARAM lParam2);extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);
if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("CPLAPP.DLL Initializing!\n");
// Extension DLL one-time initialization
if (!AfxInitExtensionModule(CplAppDLL, hInstance))
return 0;
// Insert this DLL into the resource chain
// NOTE: If this Extension DLL is being implicitly linked to by
// an MFC Regular DLL (such as an ActiveX Control)
// instead of an MFC application, then you will want to
// remove this line from DllMain and put it in a separate
// function exported from this Extension DLL. The Regular DLL
// that uses this Extension DLL should then explicitly call that
// function to initialize this Extension DLL. Otherwise,
// the CDynLinkLibrary object will not be attached to the
// Regular DLL's resource chain, and serious problems will
// result.
new CDynLinkLibrary(CplAppDLL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("CPLAPP.DLL Terminating!\n");
// Terminate the library before destructors are called
AfxTermExtensionModule(CplAppDLL);
}
hinst = hInstance;
return 1; // ok
}extern "C" int APIENTRY CPlApplet(HWND hwndCPL, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
{
int i;
NEWCPLINFO *lpCPlInfo;
i = (int) lParam1;
switch (uMsg)
{
case CPL_INIT: // first message, sent once
return TRUE;
case CPL_GETCOUNT: // second message, sent once
{
return 1;
break;
}
case CPL_INQUIRE: // third message, sent once per application
{
return 0;
}
case CPL_NEWINQUIRE:
{ lpCPlInfo->dwSize=sizeof(NEWCPLINFO);
lpCPlInfo->dwFlags=0;
lpCPlInfo->dwHelpContext=0;
lpCPlInfo->lData=0;
lpCPlInfo->hIcon=::LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(1));
strcpy(lpCPlInfo->szName,"CPL测试");
strcpy(lpCPlInfo->szInfo,"默认控制面板测试");
strcpy(lpCPlInfo->szHelpFile,"");
return 0; }
case CPL_DBLCLK: // application icon double-clicked
{
AfxMessageBox("Test");
return 0;
}
case CPL_STOP: // sent once per application before CPL_EXIT
break;
case CPL_EXIT: // sent once before FreeLibrary is called
break;
default:
break;
}
return 0;
}
代码如下;
#include "stdafx.h"
#include <afxdllx.h>
#include <CPL.h>
#include <winreg.h>#include "resource.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static AFX_EXTENSION_MODULE CplAppDLL = { NULL, NULL };HINSTANCE hinst = NULL;//控制面板接口函数CPlApplet
extern "C" int APIENTRY CPlApplet(HWND hwndCPL, UINT uMsg, LPARAM lParam1, LPARAM lParam2);extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);
if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("CPLAPP.DLL Initializing!\n");
// Extension DLL one-time initialization
if (!AfxInitExtensionModule(CplAppDLL, hInstance))
return 0;
// Insert this DLL into the resource chain
// NOTE: If this Extension DLL is being implicitly linked to by
// an MFC Regular DLL (such as an ActiveX Control)
// instead of an MFC application, then you will want to
// remove this line from DllMain and put it in a separate
// function exported from this Extension DLL. The Regular DLL
// that uses this Extension DLL should then explicitly call that
// function to initialize this Extension DLL. Otherwise,
// the CDynLinkLibrary object will not be attached to the
// Regular DLL's resource chain, and serious problems will
// result.
new CDynLinkLibrary(CplAppDLL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("CPLAPP.DLL Terminating!\n");
// Terminate the library before destructors are called
AfxTermExtensionModule(CplAppDLL);
}
hinst = hInstance;
return 1; // ok
}extern "C" int APIENTRY CPlApplet(HWND hwndCPL, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
{
int i;
NEWCPLINFO *lpCPlInfo;
i = (int) lParam1;
switch (uMsg)
{
case CPL_INIT: // first message, sent once
return TRUE;
case CPL_GETCOUNT: // second message, sent once
{
return 1;
break;
}
case CPL_INQUIRE: // third message, sent once per application
{
return 0;
}
case CPL_NEWINQUIRE:
{ lpCPlInfo->dwSize=sizeof(NEWCPLINFO);
lpCPlInfo->dwFlags=0;
lpCPlInfo->dwHelpContext=0;
lpCPlInfo->lData=0;
lpCPlInfo->hIcon=::LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(1));
strcpy(lpCPlInfo->szName,"CPL测试");
strcpy(lpCPlInfo->szInfo,"默认控制面板测试");
strcpy(lpCPlInfo->szHelpFile,"");
return 0; }
case CPL_DBLCLK: // application icon double-clicked
{
AfxMessageBox("Test");
return 0;
}
case CPL_STOP: // sent once per application before CPL_EXIT
break;
case CPL_EXIT: // sent once before FreeLibrary is called
break;
default:
break;
}
return 0;
}
aspnetwuxueyou(Where do you want to go today?) :
rundll32 shell32.dll Control_RunDLL *.cpl
这句要在那里用,我怎么注册,可不可以在程序中做?
rundll32 shell32.dll Control_RunDLL *.cpl
rundll32 shell32.dll yourCPL.cpl
你说的是怎么启动CPL,我说的是CPL不能被加载到控制面板.
原因知道了,是我忘把函数加入DEF中了.
不过也谢谢你.