|
Hi all,
I am trying to convert CString in char* using this code
CString inFName;
m_InList.GetText(i,inFName);
char *test= new char;
sprintf(test,"%s",inFName);
on a vc2005 compiler.
My problem is supoose i get "D:\COMPRESS\ziparchive.zip" in my CString variable then after converting it in char* variable the value in test is "D".
I am not getting what exactly is the problem.
Can anybody please help me in this.
Thanks in advance
|
|
|
|
|
neha.agarwal27 wrote: char *test= new char;
You have allocated memory for only one char. That why only first char is copied.
Why can't you use (LPCTSTR)inFName .
Regards,
Paresh.
|
|
|
|
|
You have two problems, I think.
1/ You are making a character pointer, but only pointing to one character. That's *1* byte of RAM. I can pretty much guarantee that your string is longer (remember it will finish with a NULL... So you will get two BYTE used, and quite likely more - so you could crash your program (if you're lucky) with string overflow. I think you're have compiled in debug mode, which will give you a little room either side of variables, which is why you're surviving this error.
2/ You are making a character pointer, but I bet your software has been compiled as UNICODE. Which means CString will be unicode too. Then you're just giving sprintf the raw CString object (not even ussing (LPCTSTR) in front of it. Frankyly, I'm surprised you don't get more than gibberish.
Answers...
If your string is not guaranteed to be US english friendly, converting it to char * is almost certainly a bad idea. What if your program was used in Korea?
If you're certain...
Look up the function WideCharToMultiByte in MSDN - and using google should be able to give you plenty of examples. If you use it with certain parameters (as described in msdn) then you can get the length of string you need to pass it. (There's a link on the msdn page to example code).
Iain.
|
|
|
|
|
If you just want character pointer you can use macros as suggested above or use GetBuffer(iLen) function.
if you are using UNICODE try using macros W2A() inside sprintf if you wish to use same codebut offcourse allocate appropriate memory before.its defined in atlconv.h
Thanks,
SandipG.
|
|
|
|
|
Hi
I've been searching all over for an answer to this questíon.
I wan't to make a plugin (Active Document Server) for Internet Explorer that takes effect based on the content type (i.e. *.myextension)
How do i register my DLL with Internet Explorer so that this will happen? I've gotten as far as being able to "Insert Object..." in Word etc. but when trying to open files in IE it just forces download. This is of course local testing.
In other words: What I need is the same feature Word and Adobe Reader implements in IE that enables IE to view .doc and .pdf files...
If you could point me towards a sample app that does this i'm in your debt!
Any help would be much appreciated!
MSDN has a sample app called ActiveDoc but that werent much help - and also their documentation on the subject seems very sparse at most.
I've also been able to find some information regarding the registry but i am not allowed to change this entry (local Vista machine running as administrator - only user allowed is "TrustedInstaller").
I'm developing in VC++ 2008.
Thanks in advance!
----------------
The Hoff
|
|
|
|
|
Hello. I'm trying to get data off of a web page. I'm able to stream in the data using CHttpFile, but I need to set some attributes first. Does anyone know how to do this? I think I have to get a document from a browser object but I can't find any examples that show me how to do this. After that it would be handy to be able to parse the HTML code into something simpler (ideally it would be the .csv format). Can anyone steer me in the right direction? Thank you.
Tom Paronis
|
|
|
|
|
Tom Paronis wrote: ideally it would be the .csv format
Really? Much of the community is using XML these days.
Tom Paronis wrote: but I need to set some attributes first.
Maybe it's just me but that needs some clarification
|
|
|
|
|
I've been able to get the IWebBrowser class to connect with the document. The next step is to set the proper variables and pull up the data I need. Once I get to that point XML may be the answer. I've never worked with it. What's nice about .csv files is that I have a delimiter class that lets me enter a number and a delimiter (a comma in this case) and extract the data I need. I'm surprised there aren't some data conversion classes out there (or in VC++). I'm sure I'm not the only person out there who has to pull data out of HTML pages. Thanks for the reply.
Tom Paronis
|
|
|
|
|
|
This does help! I should be able to pull some useful concepts out of this. Thanks.
Tom
|
|
|
|
|
|
How to design a button for clicking effect? I know how to design a button for clicked event.. dont know how to make it a clicking event. Which when the button is let go, it turns off, and while clicking, it turns on. Please help. Thanks
EvilRyu
|
|
|
|
|
EvilRyu500 wrote: How to design a button for clicking effect? I know how to design a button for clicked event.. dont know how to make it a clicking event.
What in the world does this mean?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Why don't you take a look to OnMouseDown and OnMouseUp?
You can look at coordinates of the button or sincronize with OnButtonClick.
Between the time of both mouse messages you have your "Clicking".
For example: I make a drag and drop to move graphical elements in my screen. When left mouse down I check if it hits the surface of any element. If yes... i save the name of the element and set TRUE in a bool "allowDrag". When the left mouse button is released, I search for the element of the saved name, I change its coordenates, and reset to FALSE the allowDrag.
Is something like this what you were asking for?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
I think you need to look at check boxes. You can set them to a button-like style.
So when you click once, it goes in and sends a message.
Click a second time, it goes out and sends another message.
Iain.
|
|
|
|
|
Hi!
I'm writing just in case someone might help me.
I'm to finish a huge program code using MS Visual C++ Express 2005
The problem is that I want to use a win32 function(compatible with VC++ compiler) of the equivalent linux function FCNTL(). These are some my code lines:
Sock_handle_t Server::connect ( const char * name, bool nonblocking ) <br />
{ <br />
struct addrinfo *list = NULL, *first; <br />
<br />
list = getaddrinfo_fromtext ( SOCK_STREAM, IPPROTO_TCP, name ); <br />
if( ! list ) <br />
{ <br />
throw fatal_exception(); <br />
} <br />
<br />
Sock_handle_t sock = create_socket ( AF_INET, SOCK_STREAM, IPPROTO_TCP ); <br />
int fd = sock->fd; <br />
if ( nonblocking ) { <br />
<br />
int flags = fcntl(fd, F_GETFL, 0); <br />
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0 ) return 0; <br />
} <br />
<br />
bool connect_ok = false; <br />
first = list; <br />
while (list) <br />
{ <br />
if( ! ::connect (fd, list->ai_addr, (socklen_t)list->ai_addrlen) || errno == WSAEINPROGRESS ) <br />
{
memcpy ( &sock->address, list->ai_addr, sizeof (sockaddr_in) ); <br />
connect_ok = true; <br />
break; <br />
} <br />
list = list->ai_next; <br />
} <br />
<br />
freeaddrinfo(first); <br />
if(! connect_ok ) <br />
{ <br />
close (fd); <br />
throw fatal_exception(); <br />
} <br />
<br />
return sock; <br />
} --------------------------------------------------------------------
I'm trying to do something like this with those two lines:
int flags = ioctlsocket(fd,F_GETFL,0);
if (ioctlsocket(fd,F_SETFL,reinterpret_cast<u_long*>(flags |_O_NOINHERIT))<0) return 0;
..........but I think it's not ok, any sugestion?
|
|
|
|
|
Here's my cross-platform code for Windows / Linux to set a socket as non-blocking (error checking omitted)
#ifdef WIN32
ulValue = 1;
ioctlsocket (m_hSocket, FIONBIO, &ulValue);
#else
iValue = fcntl (m_hSocket, F_GETFL);
iValue |= O_NONBLOCK;
fcntl (m_hSocket, F_SETFL, iValue);
#endif
Judy
|
|
|
|
|
hi, all,
I wanna know which function is better to use.
Objectif:
i have a FormView in which i use to add some data into a ComboBox before displaying the Form. So i hesitate beteween the OnInitUpdate , PreCreateWindow and WM_CreateWindow.
So which one is the adequate one?
Thx
-- modified at 13:29 Thursday 29th November, 2007
"The Ultimate Limit Is Only Your Imagination.
|
|
|
|
|
If you're going to add items to the ComboBox, you only choice of the three you mention is OnInitialUpdate.
The ComboBox window doesn't exist during PreCreateWindow or during Create. Only after the call to CFormView::OnInitialUpdate does the ComboBox window actually exist (valid hWnd).
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
:-Dprecreatewindow will be better
vijith vijayan
|
|
|
|
|
guys read it carefully
i hav provided odbc connection with an access db1 file
and prepared a ATM project
and used the object m_pSet in all the new classes of dialogs created by me
by passing object of view class as an arguement wen it calls dialog (on button click)
now the problem is
database updation doesnot occur wen we withdraw the money or deposit
it says database updation failed
simply how can v update data frm other class else then view
|
|
|
|
|
paresh_sarjani wrote: and used the object m_pSet
So is your view derived from CRecordView ? Is more than one table involved?
paresh_sarjani wrote: simply how can v update data frm other class else then view
Without a relevant code snippet, it would be impossible to say.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
YEAH
ITS DERIVED FRM CRECORD VIEWWWWW
AND
ONLY 1 TABLE INVOLVEDDDDDD
|
|
|
|
|
Prior to updating the record, have you called the CanUpdate() method?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|