|
When I make a cast to _bstr_t I always use
_bstr_t(str); //when str is for example a CString.
I suspect that you have a problem in the sprintf.
I saw that you pass a parameter making a cast to _bstr_t. I think that is better to make a cast to (LPCTSTR) in the sprinf....
I hope to help you Christian...
Carlos Antollini.
|
|
|
|
|
Thanks - now the sprintf is returning the right result and I pass it in like this:
records->Filter = (_bstr_t)pStr;
This still crashes in the Filter() command, although the string going in is still exactly the same string I have previously created in a single line and passed in. I've tried \n and \0 on the end of the string to no avail.
Thanks for helping
Christian
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
It would appear the ADO error only occurs if there are spaces in the field. How do I get around that ? I've put them in quotes (tried single AND double)...
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
I know that problem.
In DAO the engine supports the names with space but using this notacion [Field Name] but in ADO I saw that this don't work. Is for this that Always I use the name of the Fields without spaces. If is necesary I prefer to use Under score => _
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
>>>
CComBSTR bstrPath;
(*it)->get_FilePath(&bstrPath);
char * pStr = new char[bstrPath.Length() + 20];
memset(pStr, 0, bstrPath.Length() + 20);
sprintf(pStr, "FilePath = '%s'", (_bstr_t)bstrPath);
MessageBox(NULL, pStr, "", 0);
<<<
try this;
sprintf(pStr, "FilePath = '%s'", (char*)(_bstr_t)bstrPath);
Ben Burnett
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Thanks - that works, but this line:
records->Filter = (_bstr_t)pStr;
still crashes. The string works if I pass it in manually or through a seperate _bstr_t. Creating a _bstr_t from pStr does not help.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
What is 'records', or actually beter yet, what does type is 'Filter'.
Ben Burnett
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Records is a _RecordsetPtr. I am in ATL, no MFC support. The filter method of the Recordset works perfectly if I pass in the same string, but hard coded or created as a _bstr_t from a hardcoded value. The program crashes if I try it with the variable, if I use try/catch I get a meaningless error.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
That line crashes because (_bstr_t)pStr creates a temporary _bstr_t object which then gets deleted right away. That leaves records->Filter pointing at invalid memory. (This assumes records->Filter is a BSTR or other pointer type.)
--Mike--
http://home.inreach.com/mdunn/
A recent survey reports that 1/4 of all internet users in England surf for porn.
The other 3/4 just didn't want to admit it.
|
|
|
|
|
It's a _variant_t, but even if I create the _bstr_t seperately, it still crashes. I am certain it crashes because ADO does not recognise the command as valid, even though the syntax is the same when I pass in a hard coded value and it works.
_bstr_t s = pStr;
records->Filter = s;
Crashes
_bstr_t s = "FilePath = 'f:\\bibloi1.mdb'";
records->Filter = s;
works, even though the string I bring up in a MessageBox ( pStr) is exactly the same.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
I'm guessing you've already tried this, but maybe a little sanity check is in order;
_bstr_t s = pStr;
_bstr_t s2 = "FilePath = 'f:\\bibloi1.mdb'";
if ( s == s2 ) {
MessageBox ( "They are the same!!!");
}
Ben Burnett
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
It would appear the ADO error only occurs if there are spaces in the field. How do I get around that ? I've put them in quotes (tried single AND double)...
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
You have probably already figured this out, but if your DB allows spaces in field names (e.g. Access) most impls I've seen (i.e. Access) want you to surround them with [] brackets.
Careful though - SQL Server (which doesn't allow spaces, AFIK) will err out on you if you try to add the [].
It may be almost a rule of thumb that if you retrieve a field or table name that has an 0x20 in it you should slap the []s on 'em, and let 'em go otherwise.
|
|
|
|
|
Hi,
the explanation why
sprintf(pStr, "FilePath = '%s'", (_bstr_t)bstrPath);
doesnt show the expected result is that reference types doesnt work with va_args (functions with variable number of args - ellipsis). You have to explicitly cast via (LPCSTR) or better use _stprintf( buf, _T("<format string="" here="">"), (LPCTSTR) reference_type, ...); for supporting both unicode and ansi versions.
KB id: Q119394 convers this problem and another possible (nonportable) solution.
Cheers,
A. Focht.
|
|
|
|
|
I can't seem to get the GetMenuItemInfo function to work.
Here's my code, please tell me what I'm doing wrong.
HMENU hMenu = CreateMenu();
HMENU hPopupMenu = CreatePopupMenu();
::InsertMenu(hPopupMenu, 0, MF_STRING | MF_BYPOSITION, 0, "My PopupMenu");
::InsertMenu(hMenu, 0, MF_POPUP | MF_BYPOSITION, (UINT)hPopupMenu, "My Menu");
::SetMenu(GetSafeHwnd(), hMenu);
MENUITEMINFO mii;
memset(&mii, 0, sizeof(MENUITEMINFO));
mii.fMask = MIIM_STATE;
if(::GetMenuItemInfo(hMenu, 0, FALSE, &mii))
{
mii.fMask = mii.fMask | MIIM_STATE;
mii.fState = MFS_CHECKED;
::SetMenuItemInfo(hMenu, 0, TRUE, &mii);
}
else
AfxMessageBox("Err!");
|
|
|
|
|
You didn't set the cbSize member of MENUITEMINFO.
mii.cbSize = sizeof(MENUITEMINFO);
--Mike--
http://home.inreach.com/mdunn/
A recent survey reports that 1/4 of all internet users in England surf for porn.
The other 3/4 just didn't want to admit it.
|
|
|
|
|
There is an article listed here:
http://www.codeproject.com/listctrl/emptylv.asp
and an identical article with more comments listed here:
http://codeguru.earthweb.com/listview/EmptyLV.shtml
I have a CFormView with 2 CtrlList in there. I can't implement either article. I just want it an empty CtrlList to print somethign that tells the user it's empty right now.
By chance, can someone, anyone make this work? Please, any response any one can give me will be greatly appreciated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
What I do is write a custom draw handler, and in the CDDS_PREPAINT stage, if the list is empty, call TextOut() to display "There are no items to show" or whatever message you want.
--Mike--
http://home.inreach.com/mdunn/
A recent survey reports that 1/4 of all internet users in England surf for porn.
The other 3/4 just didn't want to admit it.
|
|
|
|
|
Hello,
How can I resize my dialog height to fit the screen - the taskbar when someone drags it to the edge of the screen? I don't want all the specifics just some explanation. Currently I have a dialog that snaps to the screen border and when it snaps to the screen edge I use SetWindowPos(NULL, 0, 0, rc.Width(), rcDesktop.Height() - bottomTaskbar, SWP_NOMOVE|SWP_NOSENDCHANGING); but it keeps resetting it back to its normal size after I call that... any ideas? Thanks in advance.
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
Type A:
// the following code is OK
CFileFind l_Blah;
l_Blah.FindSomthing("c:\\dir123\\*.abc");
while (l_Blah.FindNextFile())
{
l_Blah.GetFilePath();
}
Type B:
// and the following code is NOT OK
CFileFind l_Blah;
CFileFind l_Blah;
l_Blah.FindSomthing("c:\\dir123\\*.abc");
l_Blah.GetFilePath(); // <--- this line makes an error
while (l_Blah.FindNextFile())
{
l_Blah.GetFilePath();
}
if I use Type A, I always lose the first file that found.
What can I do????????????
Name: STR
BTW: for some of you that wished for CodeProject irc server
I create a channle on DalNet called "#CodeProject"
|
|
|
|
|
You need to do it something like this
CFileFind finder;
BOOL bContinue = finder.FindFile("bla.bla.bla");
while (bContinue)
{
...
finder.GetFilePath();
...
bContinue = finder.FindNextFile();
}
|
|
|
|
|
I need to correct something
CFileFind finder;
BOOL bContinue = finder.FindFile("bla.bla.bla");
while (bContinue)
{
...
finder.GetFilePath(); <=You will have a crash here.
...
bContinue = finder.FindNextFile();
}
this is the correct mode.
CFileFind finder;
BOOL bContinue = finder.FindFile("bla.bla.bla");
while(bContinue)
{
...
bContinue = finder.FindNextFile();}
finder.GetFilePath();
...
}
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
Hello,
Is it possible to rotate a dialog completely (title bar and all)? Say I want to tilt the dialog onto its side, possible? How? Thanks.
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
Hello,
I am tracking the TME_LEAVE mouse event in my dialog based app but even if it still has focus and I move the mouse to the listbox control then this message fires. Is there anyway to have it work like a "real" leave, say when it leaves my app? Any help is greatly appreciated.
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
What would be the best way to pass a callback function to a DLL? I want to do something like this:
In the Dll...
BOOL declspec(dllexport) __stdcall InstallKeyboardHook(HOOKPROC proc)
{
g_hKeyboardHook=SetWindowsHookEx(WH_KEYBOARD, proc, g_hInstance, 0);
return g_hKeyboardHook ? TRUE : FALSE;
}
In the executable, after LoadLibrary and GetProcAddress...
InstallKeyboardHook(MyHookProc);
LRESULT CALLBACK MyHookProc(int code, WPARAM wParam, LPARAM lParam)
{
MessageBeep((UINT)-1);
}
I don't get any errors, but I don't get any beeps from key presses, either. HELP!!!!
Thanks in advance.
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|