|
int n;
CDatabase db;
db.OpenEx("DRIVER={SQL Server};Server=(local);DATABASE=database1;UID=sa;PWD=123;");
CRecordset rs(&db);
rs.Open(AFX_DB_USE_DEFAULT_TYPE, "select * From table1 where field1="+n+""); //this line error, why?
rs.Close();
db.Close();
//where filed1=variable, how to do that?
//field1 is int type.
|
|
|
|
|
what is the error? this script could crask if your connection string is bad or if your sql is bad.
the error will clarify this.
You should change this: "select * From table1 where field1="+n+""
to
CString Temp;
Temp.Format("select * From table1 where field1='%s'", n);
rs.Open(AFX_DB_USE_DEFAULT_TYPE, Temp);
this assumes n is a string, though. If it is a number (int), change it to
Temp.Format("select * From table1 where field1=%d", n);
If n is a string, dont forget to escape all single quotes (') to double single quotes (''). This prevents errors and expoits.
// Rock
|
|
|
|
|
I have an app that has a rebar with two toolbars in it. However there is a 3D line separating the two bars and i wish them to be seamless. Any ideas?
.NET or not .NET? MFC is the question......
|
|
|
|
|
Hello,
Wondering if anyone out there has run into this before.
I'm extracting a string from a file and it HAS to have the quote in the string too. I'm adding two strings together that I have extracted from a file to get the string I need to look up.
CString id;
CString str;
str.Format("a string plus "%s"", id);
Question is how can I keep the qoutes within the string itself? Thanks in advance.
Signatures wanted for 5000 rupees each!
|
|
|
|
|
Think I figured it out. lol
CString id;
CString str;
str.Format("a string plus \"%s\"", id);
Is that correct?
Signatures wanted for 5000 rupees each!
|
|
|
|
|
Ys, it's correct
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi there,
I have written a little package viewer/builder program to extract files from the file to any directory as well as add new files to the package.
Now it was no big problem to implement drag'n'drop functionality, so that you can add files via dragging file(s) from an Explorer window INTO the program.
However I am having big problems to implement the other way round, so that you can drag a file out of a program into an Explorer window.
Does anyone have some experiences with this and maybe can provide a little example code? If its of any importance, the program itself displays the files in a standard CListView. Oh and I am not interested in d+d operations INSIDE the program, only from Program->Explorer.
Thanks in advance for any response...
|
|
|
|
|
|
I am trying to send a file over a CAsyncSocket and for this i read the file from a CFile into a BYTE or a char. I tried writing the buffer back to a file and this worked for a char as well as a BYTE. But when i tried to send over the connection (the data gets segmented into packets) i needed to stick all the packets together. Now, i didn't know how to do this with a BYTE, so there's my first question, whats the equivalent of strcat() with a BYTE?? Cause i also tried to do this with a char and i used strcat() but it only got to the three first characters or so (might this have anything to do with when u open a binary (i used an .exe) in notepad u get to see empty spaces in some places and that strcat doesn't work with this??)
Again, if someone already knows how to send files over a tcp connection(with or without MFC) please let me know.
thanks
Kuniva
--------------------------------------------
God gave man a penis and a brain but not enough blood to make both of 'em work at the same time.
|
|
|
|
|
|
Hi everyone. I originally was developing a program on a Win95 (osr2) machine, and the code below originally worked fine to write a value to the registry. I think switched to developing on a Win2000 machine, and found something odd. The code below did write to the registry fine, and I verified this with regedit, but after I reboot the machine, whatever I wrote to the registry was gone. I traced through my program many times, and I was not at any point in code erasing what was written. When I first started the program, the registry data was re-written to the registry and was read out successfully when the program was run a second time. But for some reason, whenever I rebooted the machine, the data was gone. I verified this using regedit, and ran this test several times. The reboot caused the data to be erased. This does not happen to any apps I have purchased, so I assume it is my code.
And, is limited to Win2000/NT? It did work on my Win95 development machine, as well as a friend's Win98 machine, as a release build; that is, all data was written to the registry, and was still there after reboot, and was read out succesfully every time.
This code writes to the usual hkey_current_user/software folder in the registry.
The code below writes a string the registry, which is the only data type I am writing to the registry.
<br />
long CRegKey::Write(LPCTSTR pszKey, LPCTSTR pszData)<br />
{<br />
ASSERT(m_hKey);
ASSERT(pszKey);<br />
ASSERT(pszData);<br />
ASSERT(AfxIsValidAddress(pszData, strlen(pszData), FALSE));<br />
<br />
return RegSetValueEx(m_hKey, pszKey, 0L, REG_SZ, (CONST BYTE*) pszData, strlen(pszData)+1);<br />
}<br />
|
|
|
|
|
Sounds like the key is being created with the REG_OPTION_VOLATILE option. Change that to REG_OPTION_NON_VOLATILE.
--Mike--
"Why you keep calling me Jesús? I look Puerto Rican to you?"
-- Samuel L. Jackson in Die Hard 3
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
ok, i'm really new to c++
can someone help me ?!
i made a button and i want it to run a file.
how can i do ??
thanks in advance
|
|
|
|
|
Have a look at the ShellExecute function.
Michael
|
|
|
|
|
I made a small editor whose purpose is just to load/save files with a special format. Modifications are made by any graphic editor and Bitmaps datas are exchanged via the clipboard.
The inner format of my application is a DIB (from paintlib).
Recently I decided to add the capability to save pictures with Alpha Channel. But when I paste the datas in Paint Shop Pro it says there's no Alpha Channel in the picture. I'm sure there is and I am working under 32 bits, W98 SP2. I said I am sure there is because I made the same thing with a batch converting fucntion (from file to file) and it does work fine.
I wonder wether it could come from the clipboard or Paint Shop or me . Probably I need to set something particular for Alpha Channel DIBs ?
Below is the copy to clipboard code. Has someone any idea ?
<br />
if (::OpenClipboard(NULL)) {<br />
::EmptyClipboard();<br />
<br />
HANDLE hDIB;<br />
<br />
int MemUsed = GetMemNeeded(GetWidth(), GetHeight(), GetBMI()->biBitCount);<br />
<br />
hDIB = (HANDLE)::GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, MemUsed);<br />
if (hDIB == NULL)<br />
throw (CTextException (ERR_NO_MEMORY, "Can't allocate global memory block."));<br />
<br />
long* lpCopy = (long *)::GlobalLock((HGLOBAL)hDIB);<br />
memcpy(lpCopy, m_pBMI, MemUsed);<br />
<br />
::GlobalUnlock((HGLOBAL) hDIB);<br />
<br />
::SetClipboardData(CF_DIB, hDIB);<br />
::CloseClipboard();<br />
Yarp
|
|
|
|
|
I don't believe there is any standard regarding alpha channels, apart from 32 bit images allowing for them. paintlib allows you to save the file, have you tried saving and then loading in PSP ? Having said that, most of the functions that appear to support alpha channels in paintlib are not actually working ( i.e. you can't draw with the alpha values in paintlib ). Unless you need W95 support, GDI+ pretty much makes paintlib obsolete.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Hi christian, thank you for the reply.
Indeed, I need W95 support my application is distributed from W95 to XP. The reason why I use paintlib classes is that I like the way I can handle DIB (I mean without any Windows handle - I derived my own class form their basic bitmap).
So, yes I tried saving and loading in PSP and I had the Alpha Channel properly compared to the source image (a .PNG). I dug into MSDN and I think that I should use a BitmapV5Header instead of classic a BITMAPINFOHEADER to perform the Copy/Paste (with a CF_DIBV5 format in the clipboard format instead of CF_DIB)... In which case this won't be compatible with W95 but I can deal with that for that purpose. I would like to be sure this is the good way making it. If I can find better I will look at GDI+ thank for the advice.
Yarp
|
|
|
|
|
yarp wrote:
The reason why I use paintlib classes is that I like the way I can handle DIB (I mean without any Windows handle - I derived my own class form their basic bitmap).
paintlib has a DIBSection wrapper, is this what you mean ? There are several good ones about, including one on this site, if that is all you use paintlib for. If you're using a DIB rather than a DIBSection, you may find that using DIBSections solves all your problems.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
I mainly use the painlib class as a DIB wrapper not as a DIB section. I have no need of a DIB handle, all blitting is performed through StretchDIBits.
I'll study DIBSection in MSDN it probably can help out. I already have all graphic libraries from that site and others: CXImage, CPicture, CImage, FreeImage, ImageMagick,... but studying all that stuff to find out which is the best only leads to the conclusion that each of them has quality and drawbacks.
I bet that the one which can handle properly a clipboard copy WITH alpha channel will be the one I prefer )
Thank you for your support
Yarp
|
|
|
|
|
I'm thinking that the DIBSection will allow you to use the clipboard by passing in the handle, the beauty of a DIBSection is it combines the best of a DDB and a DIB.
Good luck.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
I like the term "the beauty of" this gives me the will to try it on.
Thank you
Yarp
|
|
|
|
|
I have dialog base application with MFC.
I want task manager of win2000 to show my application,in
"processes" ,not in "applications".
Is there anyway for it?
|
|
|
|
|
You should make your dialog toolbox window:
ModifyStyleEx(WS_EX_APPWINDOW, WS_EX_TOOLWINDOW, 0);
Good Luck,
Serge
|
|
|
|
|
I put this line in Oninitdialog() but it show the application in both
"processec" and "application"???
|
|
|
|
|
thats because an application needs a process in order to work.
the application list is just the top level programs from the process list.
// Rock
|
|
|
|