|
As a rule, any MFC object that uses one of the MFC maps (especially the message map), cannot be shared between threads (since threads have separate message queues). You have to pass handles between threads.
Gary R. Wheeler
|
|
|
|
|
This should be a simple question... I have an edit box (with the 'password' style set in my resource file) in a dialog that I'd like to use to display either passwords (******) or normal, readable text. I need this behaviour to change dynamically. I tried adding/removing the ES_PASSWORD style from the control, but that didn't work. The edit box still displayed asterisks. How can I get the desired result?
Thanks!
|
|
|
|
|
SendMessage(hEdit, EM_SETPASSWORDCHAR, 0, 0); Sprudling
|
|
|
|
|
Hello,
I would like to monitor any file and directory changes in a removable
device (memory card reader). However, when I create the handle of the drive
it failed.
HANDLE hDir = CreateFile(
"g:\\", // G: is the USB memory card reader
FILE_LIST_DIRECTORY,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED,
NULL
);
Can I monitor removable device with ReadDirectoryChangesW? If so, how
do I create the handle of that device?
Thanks!
|
|
|
|
|
Synopsis: crash when run only with breakpoint (no crash if directly run), when there are no prexexisting keys in the registry for the app:
I traced the app to the last closekey where it crashes the hKey3:RegCloseKey(keyHandle3); Initially there are no keys in the registry and OpenKeyEx doesnt make them either. How come this isnt a problem when running without breakpoints (same exact scenario - no keys in registry)?
the values of LONG res = RegOpenKeyEx(keyHandle1, "MyCompany4", myApplication , are 2 and 6 - non success error codes. So should I put my RegQueryValueEx in a big if statement executed only ifOpenKeyEx is successful?
Apparently it doesnt like closing if it didnt open them (they werent present). So the closes should go into the if too, dependent on value of res(not result but res). Is this a sound idea?
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
cs.cy = 600;
cs.cx =800;
HKEY keyHandle1, keyHandle2, keyHandle3;
CString str;
DWORD valType;
DWORD xpos, ypos;
DWORD width, height;
DWORD valSize = sizeof(DWORD);
RegOpenKeyEx(HKEY_CURRENT_USER, "Software",
0, KEY_ALL_ACCESS, &keyHandle1);
LONG res = RegOpenKeyEx(keyHandle1, "MyCompany4",
0, KEY_ALL_ACCESS, &keyHandle2);
res = RegOpenKeyEx(keyHandle2, "MyApplication4",
0, KEY_ALL_ACCESS, &keyHandle3);
RegQueryValueEx(keyHandle3, "XPosition",
0, (LPDWORD) &valType, (LPBYTE) &xpos,
(LPDWORD) &valSize);
RegQueryValueEx(keyHandle3, "YPosition",
0, (LPDWORD) &valType, (LPBYTE) &ypos,
(LPDWORD) &valSize);
RegQueryValueEx(keyHandle3, "Height",
0, (LPDWORD) &valType, (LPBYTE) &height,
(LPDWORD) &valSize);
LONG result = RegQueryValueEx(keyHandle3, "Width",
0, (LPDWORD) &valType, (LPBYTE) &width,
(LPDWORD) &valSize);
if (result == ERROR_SUCCESS)
{
cs.cx = width;
cs.cy = height;
cs.x = xpos;
cs.y = ypos;
}
RegCloseKey(keyHandle1);
RegCloseKey(keyHandle2);
RegCloseKey(keyHandle3);
handles 1 and two dont complain on closing...
|
|
|
|
|
yuck.
have you considered using one of the many registry wrapper classes available here on CP ? they can get rid of all of that open/close hassle and they can really clean up your code. i'll never use the registry APIs again.
-c
"I am angry that so many of the sons of the powerful and well-placed... managed to wangle slots in Reserve and National Guard units...Of the many tragedies of Vietnam, this raw class discrimination strikes me as the most damaging to the ideal that all Americans are created equal and owe equal allegiance to their country."
--Colin Powell
|
|
|
|
|
|
You have now learned why you need error checking. You can look at ATL::CRegKey or any of the registry wrappers here for guidance on how to write the error checks.
--Mike--
Just released - RightClick-Encrypt v1.4 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
I have a work assignment wherein I have to create a COM object to contain another COM object. The inner object was not aggregatable or poolable on Win2K server, so we needed to wrap it. I'm to the point where I need to pass the function calls to the contained object. My problem is that I can't get an interface pointer to the inner objects custom interface. How would I go about this? I tried creating an IID using the value the inner object registered in the registry, but I keep getting compiler errors when I try that.
How can I create a variable of the type of the inner object's custom interface since I don't have any source/headers for this object (I do have the IDL and the DLL, of course, but that's it).
Time is of the essence here! I'm stuck!
Thanks in advance.
|
|
|
|
|
import the .dll and use the CreateInstance method.
Say the interface is named X.A
#import X.dll no_namespace
IAPtr ppA;
try {
CoInitialize(NULL);
ppA.CreateInstance(__uuidof(A));
ppA->Somemethod();
ppCrypt->Release();
CoUninitialize();
Thanks for the help,
Bill
|
|
|
|
|
The line
ppCrypt->Release();
should read
ppA->Release();
Thanks for the help,
Bill
|
|
|
|
|
I am trying to play around with an object library. Started looking at it in VB for simplicity. When I imported the type library using class wizzard to create wrappers only a few objects were inserted, when there are tons in VB object browser. Another thing I noticed when i tried to use VBs late-binding using 'createobject' i couldn't access these objects either.
Anyone any clues why I am having trouble accessing these objects from a type library, thats fine when used as a reference in VB?
Cheers
Rich
|
|
|
|
|
Hey all,
i have all these hexadecimal values(at least i think they are hexadecimal hehe) like this:
74 03 00 00 83 5b 83 8e 6d
etc...
now when you see these characters in notepad some are just blanks.
My question is, how can i make a char that contains a string for example with the hexadecimal values i just gave?
And is there an easier way then to add one character at a time because i have to make a string thats about 90 of those so it would be usefull
Thanks!
Kuniva
--------------------------------------------
|
|
|
|
|
They certainly look like hexadecimal to me. How are the values stored?
--
Andrew.
|
|
|
|
|
well they are stored binary in a file, but i dont want to extract it from there because its only a piece of it and the positions change etc... i just want to build the string from code, that has to be possible no?
Thanks
Kuniva
--------------------------------------------
|
|
|
|
|
use an ifstream to read the values and an ostringstream to build a string out of them. I have some articles on fstreams and ostringstream on CP.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
I've searched the code project site, but I have been unable to find any articles that show how to add a system dsn through code.
Could someone point me to a snippet of C++ that registers a DSN in the ODBC Data Sources?
I appreciate any help you can give me.
David Hisel -- http://www.hisel.com/
|
|
|
|
|
I don't have any code, but I can tell you how I've done it. Its really pretty easy. You need to add some entries to the system registry.
These entries define a DSN named APDB.
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\APDB]
"Driver"="C:\\WINNT\\System32\\SQLSRV32.dll"
"Server"="odyw2ksql02"
"Database"="Odyssey_APDB"
"LastUser"="obuser"
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources]
"APDB"="SQL Server"
|
|
|
|
|
Thanks!
This is very helpful, I appreciate it.
David Hisel -- http://www.hisel.com/
|
|
|
|
|
Here is some code to do this:
BOOL CreateSource(LPCSTR lpszDriver, LPCSTR lpszAttributes, BOOL bSystem )
{
char attr[500];
char driver[250];
if(lpszAttributes)
{
int mlen = strlen(lpszAttributes);
strcpy(attr,lpszAttributes);
char* ch = attr;
for (int i=0; i<mlen; i++,ch++) {if (*ch == '$') *ch = '\0';}
}
else
{
attr[0] = 0;
}
if(lpszDriver)
{
int mlen = strlen(lpszDriver);
strcpy(driver,lpszDriver);
strcat(driver,"\0");
}
else
{
driver[0] = 0;
}
WORD request;
if(bSystem) request = ODBC_ADD_SYS_DSN;
else request = ODBC_ADD_DSN;
return SQLConfigDataSource(NULL,request,driver,attr);
}
BOOL CreateAccessSource(LPCSTR lpszName, LPCSTR lpszPath, LPCSTR lpszDescription , BOOL bSystem )
{
char* szDesc;
szDesc=new char[500];
if(lpszDescription)
sprintf(szDesc,"DSN=%s$ DESCRIPTION=%s$ DBQ=%s$ FIL=MicrosoftAccess$ DEFAULTDIR=C:\\$$",lpszName,lpszDescription,lpszPath);
else
sprintf(szDesc,"DSN=%s$ DBQ=%s$ FIL=MicrosoftAccess$ DEFAULTDIR=C:\\$$",lpszName,lpszPath);
return CreateSource("Microsoft Access Driver (*.mdb)",(LPCSTR)szDesc,bSystem);
}
Pavel
Sonork 100.15206
|
|
|
|
|
This is great! Thank you.
Note: your code was mis-interpreted as HTML inside the first if block, look at the for loop to see what happened.
Could you send this via email to david at hisel dot com?
Thanks again,
David Hisel -- http://www.hisel.com/
|
|
|
|
|
I fixed it.
Pavel
Sonork 100.15206
|
|
|
|
|
My program depends on the user choosing a database, and then an images folder. Two issues arise:
If they browse to a random database, it will crash of course. If I can somehow take a look inside and see if it has a table called "tblTest" , I can potentially avert the crash. So thats
Q1 - how to peek in a db and see if its table has a particular name.
Q2 - If by chance or perversity the user chooses a random folder with none of the expected images in it, a grand crash ensues. How can I exit gracefully in case this happens? I dont mind terminating the app if need be - ideally they get a second chance to choose the right folder. The folder has a bunch of bmps in it.
I feel like there is no solution, but I have seen apps where such mistakes are forgiven...
thanks,
ns
|
|
|
|
|
ns wrote:
If by chance or perversity the user chooses a random folder with none of the expected images in it, a grand crash ensues. How can I exit gracefully in case this happens?
IMO, the real question you should be asking is "why is there a crash at all?" you should be checking for possible error situations everywhere, and acting accordingly at all times. it's a bad idea to assume every situation is a good one.
if you really need to exit immediately, try PostQuitMessage. but, that's really not much better than simply crashing, since the user has no clue as to what went wrong in either case.
-c
"I am angry that so many of the sons of the powerful and well-placed... managed to wangle slots in Reserve and National Guard units...Of the many tragedies of Vietnam, this raw class discrimination strikes me as the most damaging to the ideal that all Americans are created equal and owe equal allegiance to their country."
--Colin Powell
|
|
|
|
|
ns wrote:
If they browse to a random database, it will crash of course
You access the database through a db driver, right ? So, depending on the database (sql server, oracle, mysql, ...) you have system tables describing user tables.
And I swallow a small raisin.
|
|
|
|
|