|
I'm using CDataSource, CSession etc to work with some database.
This database is having, for example, one table with two columns.
One is a self-incrementing counter (index) and other is a value.
My task is to write a function like this:
long Add(long val) {
return index_of_val_added;
}
I'm doing it this way:
long Add(long val) {
CCommand< CAccessor< table > > t;
t.Open(session, "insert into table(val) values(-1);", NULL, NULL, DBGUID_DEFAULT, FALSE);
t.Close();
t.Open(session, "select * from table where val=-1;");
int id = t.m_id;
t.Close();
CString s;
s.Format("update table set val=%d where id=%d", val, id);
t.Open(session, s, NULL, NULL, DBGUID_DEFAULT, FALSE);
t.Close();
return id;
}
I know, that it is ugly... Could anybody show me the correct way to do it?
With the best regards, Vitaly.
|
|
|
|
|
I have a JPEG image to be printed onto the printer.How to this is possible in Windows NT
Raja sekhar
|
|
|
|
|
Use one of the classes available online ( like www.paintlib.de ) to load the image, then you'll be able to print it just like a BMP.
Christian
|
|
|
|
|
I've defined a private message in my MainFrm.h as below:
#define UWM_USER_APPLY WM_APP+17
afx_msg LRESULT OnUserApply(WPARAM wparam, LPARAM lparam);
In MainFrm.cpp, I've added this within the message-map macro:
ON_MESSAGE(UWM_USER_APPLY,OnUserApply)
I've created a property sheet, when user press "Apply" button, I do the following:
void COptionSheet::OnApply(){
GetActivePage()->UpdateData();
HWND hwnd=AfxGetMainWnd()->m_hWnd;
::SendMessage(hwnd,UWM_USER_APPLY,(WPARAM)this,0);
m_pg1.SetModified(FALSE);
m_pg2.SetModified(FALSE);
}
It work fine at debug version, when I build the release version, it'll cause "illegal operation" at the line:
::SendMessage(hwnd,UWM_USER_APPLY,(WPARAM)this,0);
If I simply changed it to a standard WM_, it'll work. For example:
::SendMessage(hwnd,WM_ENABLE,(WPARAM)this,0);
I'm using Visual C++ 6.0 with SP4 on Win98. I've tried both in NT and Win98, both have the same bad result.
Please help. Thanks in advance.
|
|
|
|
|
I've seen this happen recently - pretty much the same thing you are doing.
First 'workaround' I found was to change the macro to ON_COMMAND - which in my case didn't make a lot of sense, since my message was not a user command.
I ended up sending the message to another window and that seemed to work as a WM_MESSAGE.
I've also seen it land on the illegal instruction code (in nn, I believe) when you add a handler method and leave out a required parameter declaration (e.g. OnMyMessage() instead of OnMyMessage(UINT num)
And, as you say, only in release. Sigh... aren't macros wonderful?
|
|
|
|
|
If I had an app that used Winsock, how would I SOCKS-enable it? Any good tutorials? Thanks in advance...
--
Pikapika,
Capt. Jean-Luc Pikachu
|
|
|
|
|
The following C version works fine.
/* C Version */
#include conio.h
#include stdio.h
int main ()
{
char ch;
printf ("Type a character: ");
ch = getch();
printf ("\nYou typed: %c\n", ch);
return 0;
}
However the C++ version does not work the same way. After typing a key, I have to press the enter key to get the program going.
/* C++ version */
#include iostream
using std::cout;
using std::cin;
int main ()
{
char ch;
cout << "Type a character: ";
cin.get(ch);
// ch = cin.get();
cout << "You typed: " << ch << "\n";
return 0;
}
|
|
|
|
|
It's a messed up question with a fairly messed up answer. If you're in Windows, the iostream libraries may not work the happy way you want. That's the easy copout answer.
The longer answer (page 72 of the March 2001 issue of C/C++ User's Journal, an EXCELLENT magazine) says that you have to go down below istream/ostream to the std::streambuf class. You'll want to look for streambuf::sbumpc as a possible solution to your problem.
Unfortunately, my expertise is in VBScript (ASP 2.0) and PHP, and my attempts to use C/C++ usually make me scream stuff that would get my booted from this board. But I HAVE had the same sort of problems you've had, you're not alone, and the solution is non-obvious. That, and I didn't fully understand enough of the article to explain it to you. Check out the magazine (http://www.cuj.com/) and good luck.
--
Pikapika,
Capt. Jean-Luc Pikachu
|
|
|
|
|
Can I just second that CUJ is a fine, fine mag, ( although my March isue has not yet arrived as I am in Australia ), and that you should subscribe.
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
I'm trying to show the headers of all the records in a listbox :
1. is there a easiest/better fitted control for showing headers of records ?
2. whats my next step for loading a dialog with all Record Data after a row had been selected ? How do i get the index of the Record (is there a return value in ListBox ??) or, How to retrive the Record from the ListBox ?
Thanks for your help,
Ariel.
|
|
|
|
|
Hi there,
Well i'm trying to figure out a way to lock a record when i'm editting it and it seems i can't find the way.
First, I'm using ODBC and my DB is both in Access and FoxPro - i'm not sure wether the lock of the record is handled by ODBC Drivers or the DB itself - so if somone can help me with that i'll be more than happy.
Second, I'm trying to change the CRecordset::SetLockingMode(CRecordset::pessimistic) and i get an exception which tells me i'm actualy back to default CRecordset::Optimistic (Locking Mode) - those this have to do with my ODBC Driver or my Access DB.
Third, is there a flag in CRecordset which tells me whether the Record is edited by another user or only the ODBC/DB (???) handles and know it ?
Actually what i'm asking in a one sentence is : Can i check if a record is edited by another user in another process or i have to put my own Semaphore for this ???
Thank you alot for reading all this and much more if help given,
Ariel.
|
|
|
|
|
First, I think you read this writings.
I want to know how to get ip address and customer id(client id).
so, I want to put in data(CString variables) value made from above structure.
I don't know this at all.
Please reply this question quickly.
|
|
|
|
|
Can you read?
WSADATA wsaData;
struct sockaddr_in sock;
CString strHostname;
int lLen = 255;
WSAStartup(0x0101, &wsaData);
gethostname(strHostname.GetBuffer(lLen), lLen);
HOSTENT * lpHost = gethostbyname(strHostname.GetBuffer(lLen));
memcpy(&(sock.sin_addr), lpHost->h_addr_list[0], lpHost->h_length);
TRACE2 ("Host Name: %s IP address : %s\n",strHostname, inet_ntoa(sock.sin_addr));
WSACleanup();
Considderd to be the worlds fastest knoppenbonker.
10 Months of working experience with the worlds fastest copie paster(about 2000 lines a minute).
And experience with the one and only NewEra Guru.
|
|
|
|
|
I want to put in data(CString)...
Would you do me a favor?
|
|
|
|
|
I want to pass an array of strings from a VB application to a C++/MFC DLL
I then want to update that array in the DLL and pass it back to the VB app
I know how to pass a string to the DLL but not an array of strings.
Can anyone help me out.
Thanks
|
|
|
|
|
You know the complex bit about passing strings (ie: as BSTR's)
To pass an array of strings you need to use a SAFEARRAY.
As this can be a bit fiddley I have suggested to people in the
past to instead write a function AddString which builds up the
array and then one to Execute to do the action to the array.
Jules
|
|
|
|
|
I have tried to use the SAFEARRAY, and I can pass to the DLL an array of integers or double etc.
I do have trouble trying to pass strings.
do you have an example of the function AddString?
If so, that would be great
thanks
|
|
|
|
|
I don't understand how to retrieve text from a CEdit control using GetLine member function. In particular I need to know what kind of buffer is needed. I declared: char buffer[40]; and then how can I use this buffer within the GetLine function?? When I started my program I obtain a page error message. HELP ME!!
|
|
|
|
|
ummmm
msdn ... cedit class members ... getline()
read topic
type code
click build button
run app
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
int iLineNumber;
CString strLine;
//////////////////////////////////////////////////////////////
// Get the currently selected line number.
//////////////////////////////////////////////////////////////
iLineNumber = m_edit.LineFromChar(-1);
//////////////////////////////////////////////////////////////
// Get the text of the current line number.
//////////////////////////////////////////////////////////////
strLine = m_edit.GetLine(iLineNumber);
If you have just a normal CEdit control then GetWindowText will
get ALL the text for you.
Also of interest are LineIndex and LineLength.
Note that some of these methods return the 'position' in the string
where the new lines are and NOT the 'line number'.
Jules
|
|
|
|
|
This is an extreamly newbie question. New to C++ and Visual C++.
I need to write a progra, that can be used a a math tutor for a young student
The program has to display 2 random numbers that are to be added, such as:
247
+129
-----
The program has to pause while the student is working on the problem. When the student is ready
to check his or her answer, a key can be pressed and the program will display the correct Solution.
247
+129
-----
376
It should then Say : Timmy you got it Right! Or Timmy, thats not the right answer, Try again.
NOTE:Forgot to mention, that it needs to ask for the users name :P
Some help would be apperciated.
|
|
|
|
|
Suppose you have to generate numbers in the range [100, 500]
Then you could write something similar to:
// initialize random number generator
// otherwise every time the app is run
// you get the same numbers
srand((unsigned)time(NULL));
int a = 100 + rand()*(500-100)/RAND_MAX;
int b = ... // the same
The function rand() returns an integer in the range [0, RAND_MAX] so you have to adjust the result to fit your range. Another possibility, if your range is much smaller than RAND_MAX, is to write:
int a = 100 + rand()%(500-100);
I don't know which is best.
Cheers,
Paolo.
|
|
|
|
|
Does anyone knows where I could find an example on Multidimentional CMap. What I am trying to accomplish is the following:
Example:
Department ASD
Workers
Worker 1
Worker 2
Worker 3
Department Accounting
Workers
Worker 1
Worker 2
Both of these should be searchable by string. To accomplish the inner dimmention I have done the following:
CMap < CString, LPCSTR, CWorker, CWorker > m_Worker;
I have tried to get the outer dimmention with the following:
CTypedPtrMap < CMapStringToOb,CString, CMap < CString, LPCSTR, CWorker, CWorker > > m_Department;
where CWorker is a class containing two _bstr_t for the first and last name.
The error I was getting was that the CMap does not have a copy constructor. Does anyone knows how to accomplish this that is clean and logical?
Thanks for your help, John.
|
|
|
|
|
Try something like:
typedef CMap<cstring, const="" char*,="" cstring,="" char*=""> lower_map;
CMap<cstring, const="" char*,="" lower_map*,="" lower_map*="">;
That should work.
|
|
|
|
|
Hi, I've been trying to implement a floating palette bar, ala Photoshop with MFC, alas, to no avail.. the examples from Microsoft, CtrlBar & cmnctrl1 i think.. don't quite fit with code generated using MFC Wizard. Can anyone point me to a sample code that implements this feature using code generated with MFC Wizard?
Thanks.
|
|
|
|
|