Re: VS2005 compatibility
- From: Long <Long@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 5 Sep 2006 12:26:02 -0700
I must make some mistakes when typing the second examples, i.e. ValueDW(),
instead of copying and pasteing the code. I think I did the same as you did
except my program cannot run. This is what I did.
1. Create a Smart Device project.
2. Remove the default device and select my device: Colibri.
3 Select Console Application. ATL, MFC and Empty project are unchcked.
4. Then finish thw wizard. Everything is in default settings.
5. Then type in my code, compile and run with or without debugging.
These projects do not need additional libraries. But I don't know what
default libs they use. So I don't think I change them. Besides I use the
same workspace and settings to compile the two examples, one can run and the
other doesn't. If that is not a problem from VS2005, would that comes from
BSP or its SDK?
"Paul G. Tobey [eMVP]" wrote:
And a thought arises. What libraries are you linking with? Did you change.
anything from the default generated by the VS2005 new project wizard to
target Smart Devices?
Paul T.
"Long" <Long@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:491D9629-7A31-4251-AA3F-DCF47D434F4A@xxxxxxxxxxxxxxxx
Thanks Paul,
Here is the code without problems.
#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
int _tmain(int argc, _TCHAR* argv[])
{
wprintf(L"Starting...\n");
HKEY m_hKey;
int m_Index;
LPBYTE m_lpbValue; // last value read, if any
//TCHAR szValue[MAX_PATH];
DWORD ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Comm", 0, KEY_READ,
&m_hKey);
DWORD dwValue = 1;
DWORD dwLen = sizeof(DWORD);
ret = RegQueryValueEx(m_hKey, L"BootCount", NULL, NULL, (LPBYTE)&dwValue,
&dwLen);
ret = RegSetValueEx(m_hKey, L"Test", 0, REG_DWORD, (LPBYTE)&dwValue,
sizeof(DWORD));
ret = RegCloseKey(m_hKey);
ret = RegFlushKey(HKEY_LOCAL_MACHINE);
Sleep(1000);
wprintf(L"Exiting...\n");
return 0;
}
Here is the code that can be compliled successfully, but not run.
//CReg class RegHelper.h
#pragma once
/////////////////////////////////////////////////////////////////////////////
// CReg: Registry helper class
/////////////////////////////////////////////////////////////////////////////
#define MyFree(p) { if(p) LocalFree(p); }
class CReg
{
private:
HKEY m_hKey;
int m_Index;
LPBYTE m_lpbValue; // last value read, if any
public:
BOOL Create(HKEY hkRoot, LPCTSTR pszKey) {
DWORD dwDisp;
return ERROR_SUCCESS==RegCreateKeyEx(hkRoot, pszKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &m_hKey, &dwDisp);
}
BOOL Open(HKEY hkRoot, LPCTSTR pszKey, REGSAM sam=KEY_READ) {
return ERROR_SUCCESS==RegOpenKeyEx(hkRoot, pszKey, 0, sam, &m_hKey);
}
CReg(HKEY hkRoot, LPCTSTR pszKey) {
m_hKey = NULL;
m_Index = 0;
m_lpbValue = NULL;
Open(hkRoot, pszKey);
}
CReg() {
m_hKey = NULL;
m_Index = 0;
m_lpbValue = NULL;
}
~CReg() {
if(m_hKey) RegCloseKey(m_hKey);
MyFree(m_lpbValue);
}
void Reset() {
if(m_hKey) RegCloseKey(m_hKey);
MyFree(m_lpbValue);
m_hKey = NULL;
m_Index = 0;
m_lpbValue = NULL;
}
operator HKEY() { return m_hKey; }
BOOL IsOK(void) { return m_hKey!=NULL; }
BOOL EnumKey(LPTSTR psz, DWORD dwLen) {
if(!m_hKey) return FALSE;
return ERROR_SUCCESS==RegEnumKeyEx(m_hKey, m_Index++, psz, &dwLen, NULL,
NULL, NULL, NULL);
}
BOOL EnumValue(LPTSTR pszName, DWORD dwLenName, LPTSTR pszValue, DWORD
dwLenValue) {
DWORD dwType;
if(!m_hKey) return FALSE;
dwLenValue *= sizeof(TCHAR); // convert length in chars to bytes
return ERROR_SUCCESS==RegEnumValue(m_hKey, m_Index++, pszName, &dwLenName,
NULL, &dwType, (LPBYTE)pszValue, &dwLenValue);
}
BOOL ValueSZ(LPCTSTR szName, LPTSTR szValue, DWORD dwLen) {
if(!m_hKey) return FALSE;
dwLen *= sizeof(TCHAR); // convert length in chars to bytes
return ERROR_SUCCESS==RegQueryValueEx(m_hKey, szName, NULL, NULL,
(LPBYTE)szValue, &dwLen);
}
DWORD ValueBinary(LPCTSTR szName, LPBYTE lpbValue, DWORD dwLen) {
if(!m_hKey) return FALSE;
DWORD dwLenWant = dwLen;
if(ERROR_SUCCESS==RegQueryValueEx(m_hKey, szName, NULL, NULL, lpbValue,
&dwLen))
return dwLen;
else
return 0;
}
LPCTSTR ValueSZ(LPCTSTR szName);
LPBYTE ValueBinary(LPCTSTR szName) {
return (LPBYTE)ValueSZ(szName);
}
DWORD ValueDW(LPCTSTR szName, DWORD dwDefault=0) {
if(!m_hKey) return FALSE;
DWORD dwValue = dwDefault;
DWORD dwLen = sizeof(DWORD);
RegQueryValueEx(m_hKey, szName, NULL, NULL, (LPBYTE)&dwValue, &dwLen);
return dwValue;
}
BOOL SetSZ(LPCTSTR szName, LPCTSTR szValue, DWORD dwLen) {
//Prefix
if(!m_hKey) return FALSE;
//
return ERROR_SUCCESS==RegSetValueEx(m_hKey, szName, 0, REG_SZ,
(LPBYTE)szValue, sizeof(TCHAR)*dwLen);
}
BOOL SetSZ(LPCTSTR szName, LPCTSTR szValue) {
return SetSZ(szName, szValue, 1+lstrlen(szValue));
}
BOOL SetDW(LPCTSTR szName, DWORD dwValue) {
//Prefix
if(!m_hKey) return FALSE;
//
return ERROR_SUCCESS==RegSetValueEx(m_hKey, szName, 0, REG_DWORD,
(LPBYTE)&dwValue, sizeof(DWORD));
}
BOOL SetBinary(LPCTSTR szName, LPBYTE lpbValue, DWORD dwLen) {
//Prefix
if(!m_hKey) return FALSE;
//
return ERROR_SUCCESS==RegSetValueEx(m_hKey, szName, 0, REG_BINARY,
lpbValue, dwLen);
}
BOOL SetMultiSZ(LPCTSTR szName, LPCTSTR lpszValue, DWORD dwLen) {
return ERROR_SUCCESS==RegSetValueEx(m_hKey, szName, 0, REG_MULTI_SZ,
(LPBYTE)lpszValue, sizeof(TCHAR)*dwLen);
}
BOOL DeleteValue(LPCTSTR szName) {
//Prefix
if(!m_hKey) return FALSE;
//
return ERROR_SUCCESS==RegDeleteValue(m_hKey, szName);
}
BOOL DeleteKey(LPCTSTR szName) {
if(!m_hKey) return FALSE;
return ERROR_SUCCESS==RegDeleteKey(m_hKey, szName);
}
};
//CReg class
#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include "RegHelper.h"
int _tmain(int argc, _TCHAR* argv[])
{
CReg reg;
reg.Open(HKEY_LOCAL_MACHINE, L"Comm");
DWORD dwCount = reg.ValueDW("BootCount", 0);
}
Any idea?
"Paul G. Tobey [eMVP]" wrote:
You'll have to show that code then. You're probably making them instance
methods or something. There's no 'this' pointer passed to registry
calls...
Paul T.
"Long" <Long@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5207C64C-5E5A-4DF4-811A-D2DED88FE531@xxxxxxxxxxxxxxxx
It is a Smart Device project. It works well when I code it as C style,
such
as calling the Registry APIs directly. But when I wrap those APIs in a
class, it failed.
"Paul G. Tobey [eMVP]" wrote:
It would be something like you're building the application to target
the
wrong processor type or something of that sort, not some sneaky
setting
buried five layers deep in the project properties. You *did* build it
as
a
Smart Device project, not a desktop project, right? If it's a desktop
EXE,
it's *not* a valid Windows CE executable.
Paul T.
"Long" <Long@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E3D1B65E-2C86-4755-AFFE-7921F1908B36@xxxxxxxxxxxxxxxx
Thanks Robert. That is what I am thinking the settings of VS2005
C++
may
be
the cause of my problem. There is no problem for the identity of my
device,
Colibri PXA270, since the image I built with their BSP works
perfectly.
The
only strange thing is there is no problem to call the APIs in C
style,
i.e.
Registry APIs. But when I wrap around those APIs in a class like
the
class
CReg dose in the PB's source, it wouldn't work.
"r_z_aret@xxxxxxxxxxxx" wrote:
I'm sure I'm not the only developer who uses C++ objects in code
that
runs under CE 5. So that is not the problem.
I _think_ the "not a valid ce program" shows up very early, and
thus
indicates something wrong in the way you built the executable,
rather
than in the code you used.
My hunch is you're doing something "silly", like using the wrong
settings. Is the actual device a Colibri PXA270? Are you sure that
kit
works with VS 2005? Are you building for an actual device or an
emulator (I've barely even tried VS 2005, so maybe this is no
longer
relevant)? Are you using the right version of VS 2005 (definitely
not
the freebie, but I'm not sure beyond that).
On Sat, 2 Sep 2006 15:20:02 -0700, Long
<Long@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I am using Colibri PXA270 Kit and SDK in CE5. I did not use MFC
in
the
examples, since MFC projects cannot even run on the target. In
the
IDE
of
VS2005, it shows "Cannot start \Program Files\XXX" in debug mode.
If
I
run
the exe directly in the target, it saids the exe is not a valid ce
program.
- Follow-Ups:
- Re: VS2005 compatibility
- From: Paul G. Tobey [eMVP]
- Re: VS2005 compatibility
- References:
- Re: VS2005 compatibility
- From: r_z_aret
- Re: VS2005 compatibility
- From: Long
- Re: VS2005 compatibility
- From: r_z_aret
- Re: VS2005 compatibility
- From: Long
- Re: VS2005 compatibility
- From: Paul G. Tobey [eMVP]
- Re: VS2005 compatibility
- From: Long
- Re: VS2005 compatibility
- From: Paul G. Tobey [eMVP]
- Re: VS2005 compatibility
- From: Long
- Re: VS2005 compatibility
- From: Paul G. Tobey [eMVP]
- Re: VS2005 compatibility
- Prev by Date: Re: how to detect the windows manager is ready
- Next by Date: Re: VS2005 compatibility
- Previous by thread: Re: VS2005 compatibility
- Next by thread: Re: VS2005 compatibility
- Index(es):
Relevant Pages
|