Re: Soft Input Panel SIP
- From: schliz <schliz11@xxxxxxxxx>
- Date: Mon, 11 Jun 2007 23:07:00 -0700
On 11 Jun., 21:03, Paul Monson <p...@xxxxxxxxxx> wrote:
Why do you have _tmain and DllRegisterServer? _tmain is for .EXEs and
DllRegisterServer is for .DLLs. Which one are you trying to build?
Does your device have the MFC DLL installed?
Paul Monson
Intrinsyc
schliz wrote:
I am working with Visual C++ 2005 Windows CE armV4i.
I try to setup a Soft Input Panel. I tried code out of Bolings book
Programming Microsoft Windows ce.net. The program is working, but it
is without MFC support.
I tried to setup a new projekt Win32 Smart Device Projekt -- DLL add
support for MFC.
I added the code of the example:
Code:
----------------------------------------------------
#include "stdafx.h"
#include "kbd.h"
#include <windows.h>
#include <commctrl.h>
#include "NumPanel.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// The one and only application object
CWinApp theApp;
using namespace std;
///
//
// GUID defines for my input method. Create a new one with GUIDGEN.
//
const GUID CLSID_NumPanel2 =
{ 0xc8311f61, 0x12df,0x4107,{0xb5,0xea,0xb0,0xb0,0xd5,0x5c,0xec,
0x50}};
const TCHAR szCLSIDNumPanel2[] =
TEXT ("{C8311F61-12DF-4107-B5EA-B0B0D55CEC50}");
const TCHAR szFriendlyName[] = TEXT ("Numeric Keypad");
///
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
printf("main");
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(),
0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
}
return nRetCode;
}
///---------------------------------------------------------------------------------
//
======================================================================
// DllGetClassObject - Exported function called to get pointer to
// Class factory object.
//
STDAPI DllGetClassObject (REFCLSID rclsid, REFIID riid, LPVOID *ppv) {
MyClassFactory *pcf;
HRESULT hr;
// See if caller wants us.
if (IsEqualCLSID (rclsid, CLSID_NumPanel2)) {
// Create IClassFactory object.
pcf = new MyClassFactory();
if (pcf == NULL)
return E_OUTOFMEMORY;
// Call class factory's query interface method.
hr = pcf->QueryInterface (riid, ppv);
// This will cause an obj delete unless interface found.
pcf->Release();
return hr;
}
return CLASS_E_CLASSNOTAVAILABLE;
}
//
======================================================================
// DllCanUnloadNow - Exported function called when DLL can unload
//
STDAPI DllCanUnloadNow () {
if (g_DllCnt)
return S_FALSE;
return S_OK;
}
//
======================================================================
// DllRegisterServer - Exported function called to register the server
//
STDAPI DllRegisterServer () {
TCHAR szName[MAX_PATH+2];
TCHAR szTmp[128];
DWORD dwDisp;
HKEY hKey, hSubKey;
INT rc;
printf("reg server");
// GetModuleFileName (hInst, szName, sizeof (szName));
HMODULE hInst
= ::GetModuleHandle(NULL); //-----------------------------------------------------
// if NULL Abfrage
GetModuleFileName (hInst, szName, sizeof (szName));
// Open the key.
wsprintf (szTmp, TEXT ("CLSID\\%s"), szCLSIDNumPanel2);
rc = RegCreateKeyEx (HKEY_CLASSES_ROOT, szTmp, 0, TEXT(""),
0, 0, NULL, &hKey, &dwDisp);
if (rc != ERROR_SUCCESS)
return E_FAIL;
// Set the friendly name of the SIP.
RegSetValueEx (hKey, TEXT (""), 0, REG_SZ, (PBYTE)szFriendlyName,
(lstrlen (szFriendlyName)+1) * sizeof
(TCHAR));
// Create subkeys.
// Set the module name of the SIP.
rc = RegCreateKeyEx (hKey, TEXT ("InProcServer32"), 0, TEXT(""),
0, 0, NULL, &hSubKey, &dwDisp);
rc = RegSetValueEx (hSubKey, TEXT (""), 0, REG_SZ, (PBYTE)szName,
(lstrlen (szName)+1) * sizeof (TCHAR));
RegCloseKey (hSubKey);
// Set the default icon of the server.
RegCreateKeyEx (hKey, TEXT ("DefaultIcon"), 0, TEXT(""),
0, 0, NULL, &hSubKey, &dwDisp);
lstrcat (szName, TEXT (",0"));
RegSetValueEx (hSubKey, TEXT (""), 0, REG_SZ, (PBYTE)szName,
(lstrlen (szName)+1) * sizeof (TCHAR));
RegCloseKey (hSubKey);
// Set the flag indicating this is a SIP.
RegCreateKeyEx (hKey, TEXT ("IsSIPInputMethod"), 0, TEXT(""),
0, 0, NULL, &hSubKey, &dwDisp);
lstrcpy (szTmp, TEXT ("1"));
RegSetValueEx (hSubKey, TEXT (""), 0, REG_SZ, (PBYTE)szTmp, 4);
RegCloseKey (hSubKey);
RegCloseKey (hKey);
return S_OK;
}
//
======================================================================
// DllUnregisterServer - Exported function called to remove the server
// information from the registry
//
STDAPI DllUnregisterServer() {
INT rc;
TCHAR szTmp[128];
wsprintf (szTmp, TEXT ("CLSID\\%s"), szCLSIDNumPanel2);
rc = RegDeleteKey (HKEY_CLASSES_ROOT, szTmp);
if (rc == ERROR_SUCCESS)
return S_OK;
return E_FAIL;
}
//
**********************************************************************
// MyClassFactory Object implementation
//----------------------------------------------------------------------
// Object constructor
MyClassFactory::MyClassFactory () {
m_lRef = 1; // Set ref count to 1 on create.
return;
}
//----------------------------------------------------------------------
// Object destructor
MyClassFactory::~MyClassFactory () {
return;
}
//----------------------------------------------------------------------
// QueryInterface - Called to see what interfaces this object supports
STDMETHODIMP MyClassFactory::QueryInterface (THIS_ REFIID riid,
LPVOID *ppv) {
// If caller wants our IUnknown or IClassFactory object,
// return a pointer to the object.
if (IsEqualIID (riid, IID_IUnknown) ||
IsEqualIID (riid, IID_IClassFactory)) {
*ppv = (LPVOID)this; // Return pointer to object.
AddRef(); // Increment ref to prevent delete on
return.
return NOERROR;
}
*ppv = NULL;
return (E_NOINTERFACE);
}
//----------------------------------------------------------------------
// AddRef - Increment object ref count.
STDMETHODIMP_(ULONG) MyClassFactory::AddRef (THIS) {
ULONG cnt;
cnt = (ULONG)InterlockedIncrement (&m_lRef);
return cnt;
}
//----------------------------------------------------------------------
// Release - Decrement object ref count.
STDMETHODIMP_(ULONG) MyClassFactory::Release (THIS) {
ULONG cnt;
cnt = (ULONG)InterlockedDecrement (&m_lRef);
if (cnt == 0)
delete this;
return cnt;
}
//----------------------------------------------------------------------
// LockServer - Called to tell the DLL not to unload even if use count
is 0
STDMETHODIMP MyClassFactory::LockServer (BOOL fLock) {
if (fLock)
InterlockedIncrement (&g_DllCnt);
else
InterlockedDecrement (&g_DllCnt);
return NOERROR;
}
//----------------------------------------------------------------------
// CreateInstance - Called to have class factory object create other
// objects
STDMETHODIMP MyClassFactory::CreateInstance (LPUNKNOWN pUnkOuter,
REFIID riid,
LPVOID *ppv) {
MyIInputMethod *pMyIM;
HRESULT hr;
if (pUnkOuter)
return (CLASS_E_NOAGGREGATION);
if (IsEqualIID (riid, IID_IUnknown) ||
IsEqualIID (riid, IID_IInputMethod) ||
IsEqualIID (riid, IID_IInputMethod2)) {
// Create Input method object.
pMyIM = new MyIInputMethod();
if (!pMyIM)
return E_OUTOFMEMORY;
// See if object exports the proper interface.
hr = pMyIM->QueryInterface (riid, ppv);
// This will cause an obj delete unless interface found.
pMyIM->Release ();
return hr;
}
return E_NOINTERFACE;
}
//
**********************************************************************
// MyIInputMethod Object implementation
//----------------------------------------------------------------------
// Object constructor
MyIInputMethod::MyIInputMethod () {
m_lRef = 1; // Set ref count to 1 on create.
g_DllCnt++;
return;
}
//----------------------------------------------------------------------
// Object destructor
MyIInputMethod::~MyIInputMethod () {
g_DllCnt--;
return;
}
//----------------------------------------------------------------------
// QueryInterface - Called to see what interfaces this object supports
STDMETHODIMP MyIInputMethod::QueryInterface (THIS_ REFIID riid,
LPVOID *ppv) {
// If caller wants our IUnknown or IID_IInputMethod2 object,
// return a pointer to the object.
if (IsEqualIID (riid, IID_IUnknown) ||
IsEqualIID (riid, IID_IInputMethod) ||
IsEqualIID (riid, IID_IInputMethod2)){
// Return ptr to object.
*ppv = (IInputMethod *)this;
AddRef(); // Increment ref to prevent delete on
return.
return NOERROR;
}
*ppv = NULL;
return (E_NOINTERFACE);
}
//----------------------------------------------------------------------
// AddRef - Increment
...
Erfahren Sie mehr »- Zitierten Text ausblenden -
- Zitierten Text anzeigen -
First of all thank you all for your reply!
I have to create a Soft input panel, the reason why I would like to
have MFC included is,I have got source code for a Keyboard window CWnd
and its functionality, which I want to use. I have written some
applications including MFC statically linked - they run on my device.
I thought about creating a new dll, and included the above mentioned
code.
The book code contains a DLLmain function, the rest of the functions I
have included in my code, and there is a separate cpp and h file,
which is responsible for the window, (I thought replacing with my code
I already have):
code:
_____________
//
======================================================================
// DllMain - DLL initialization entry point
//
BOOL WINAPI DllMain (HANDLE hinstDLL, DWORD dwReason,
LPVOID lpvReserved) {
hInst = (HINSTANCE)hinstDLL;
return TRUE;
}_______________
The choice I mad for the dll was: new projekt Win32 Smart Device
Projekt -- DLL add
support for MFC. I got:
code:
________________________
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
printf("main");
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL),
NULL, ::GetCommandLine(),
0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed
\n"));
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
}
return nRetCode;
}
____________________________________
Which project do I have to create?
What do I have to do?
Thank you for your help
Georg
.
- Follow-Ups:
- Re: Soft Input Panel SIP
- From: schliz
- Re: Soft Input Panel SIP
- From: Paul Monson
- Re: Soft Input Panel SIP
- References:
- Soft Input Panel SIP
- From: schliz
- Re: Soft Input Panel SIP
- From: Paul Monson
- Soft Input Panel SIP
- Prev by Date: Re: How to create shortcut to a file not in deployment project
- Next by Date: Re: How to Disable Windows CE 6.0 from Stealing COM1
- Previous by thread: Re: Soft Input Panel SIP
- Next by thread: Re: Soft Input Panel SIP
- Index(es):
Relevant Pages
|
Loading