|
What compiler are you using ? You can derive a class from a control class and put whatever child controls you want on there.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
dear Christian
thank you for your help
i use microsoft visual c++ 6 and i am a newer in this
if you can explane to me step by step >> thanks for you time
|
|
|
|
|
To be honest, really your best bet is to look amongst the articles on this site. They come with full source code and an explanation, and will be more in depth than any explanation I would come up with for your benefit within a forum post.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,
I am using this code
char * buffer = "";
_getcwd(buffer, _MAX_PATH);
to get my applications directory. However it give a 'the memory could not be "written"' error. Is there a better way to get the applications directory.
|
|
|
|
|
char buffer[_MAX_PATH];
_getcwd(buffer, _MAX_PATH);
|
|
|
|
|
Do realize that if the user set the working directory with a shortcut, this will return that path and not the path of the executing process. For the latter, use the following:
TCHAR filename[MAX_PATH];<br />
::GetModuleFileName(hModule, filename, MAX_PATH);
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Vis C/C++ 6.0 Vis Studio
I am receiving web pages using recv().
I am looping and receiving chunks of the page
and am concatinating them to a buffer.
I get the whole file but the loop hangs because
I have no detection of the end of file.
If I manually close the socket, I always have the
full file.
I have tried the recv() MSG_PEEK flag inside of the loop
to detect the end of the file, but I don't seem to be
able to get it to work. It hangs as well.
I've seen some code on CodeProject that looks for
2 consequtive CRLFs but that really only works if you
are only expecting a Header.
Any help would be much appreciated.
Thanks,
Robert
|
|
|
|
|
I have no experience at all, but did you try using http / 1.0 or add the "Connection: close" header?
|
|
|
|
|
Hi zzattack,
Thanks for reply.
I am using the recv() function and it
is a blocking call. Since I do not
know the size of the file that is coming,
I keep calling recv() to get the full file.
What happens is that when I call it the
final time, the call blocks - and I am hung there.
Robert
|
|
|
|
|
Hi zzatack,
Got it working!
I added Connection: close
as you recommended.
I guess that the recv() function was continuing to
wait for more packets since the connection was still open.
I'm not sure how you can say,
"I have no experience at all..."
when in fact you put your finger right
on the problem!!
Thanks again
Robert
|
|
|
|
|
Haha, cool, good to hear. I'll try to explain how I think it works.
Actually your recv() function returns when it has read what you wanted (like 4096 or 8192 bytes etc.), or if the connection closes. But, if there's not enough data left to fill the buffer (eof), recv() keeps waiting, and the connection remains opened so that more data can be sent and added to the buffer later.
By default on HTTP/1.0 the connection is closed, but with HTTP/1.1 it remains opened unless "Connection: close" was sent along with the headers. Therefor, recv() returns only when the server closes the connection because of a timeout. That might take minutes, and your code inded appears to hang
I meant I have no c/c++ experience, only a bit of the HTTP protocol which I learned fom mIRC scripting. I was actually looking at the boards for tutorials . Anyway, have fun.
|
|
|
|
|
Receive returns the number of bytes now in buffer(Received). If it is 0(zero) Then received all.You can turn back.
|
|
|
|
|
Hi Ajesh,
Thank-you for reply.
Unfortunately what is happening is that the
recv() call is blocking - it is hung, so I don't
get any "number of bytes" to even look at!
If I manually close the socket, then I have
the full file, but a 'manual close' approach
would be very undesirable to implement.
Any other suggestions?
Many thanks,
Robert
|
|
|
|
|
I am new to Visual C++.
1. Dialog application
2. Input screen built and working
3. Class Orders built. Base class generic CWnd. Contains data about orders and functions that validate them.
4. Can't use class Orders because I can't figure out where to construct it. In a console application, I would construct it in main(). Where can I execute a constructor for class Orders in a dialog or SDI app under VC++?
5. If I can construct an object of class Orders, I can then move on to exploring the use of the class. Until then I am stuck.
6. I suspect I am missing something very basic here. Any help is appreciated.
|
|
|
|
|
That greatly depends on when you want to use the Orders class. If you want to use it right away, instantiate the class in the OnInitDialog function
|
|
|
|
|
I created an absolutely barebones dialog project called Store to figure this out.
VC++ created two classes: CStoreApp and CStoreDlg.
I created an additional class Orders based on generic CWnd. I added no code. It compiled and executed OK.
My understanding is that I should use the OnInitDialog function of class CStoreDlg to create an instance of class Orders. Is that correct?
ATTEMPT #1:
ACTION:Added the following to OnInitDialog: Orders buy;
RESULT: Errors- 1)Orders undeclared identifier, 2) missing ";" before identifier 'buy', 3)'buy'undeclared identifier
ATTEMPT #2:
Added the following to OnInitDialog: Orders::orders buy;
RESULT: Errors- 1) Orders is not aclass or namespace, 2) Orders undeclared identifier, 3) Missing ';' before identifier 'buy' 4) 'buy' undeclared identifier.
I am obviously missing something critical.
|
|
|
|
|
You problably need to add #include "name of the orders class .h file" into your CStoreDlg .h file
|
|
|
|
|
Thanks. That worked. Also - from OnInitDialog - accessed a variable of Orders object and called a function member of the Orders object. Small steps, but they add up. Thanks again.
|
|
|
|
|
You are welcome. Everyone has to start somewhere. Good luck!
|
|
|
|
|
You probably like access to your Orders object from all functions in the Dialog. In this case it makes sense to declare your orders object as amember variable. Member variables should be defined in the class declaration (in the header file). Then the object can be used inside the class.
|
|
|
|
|
I think I am having trouble moving from use of main() in console based C++ to VC++. In console I could do the following:
int main()
{
Limits Lim;
Transaction Tran;
int iResult;
iResult = Lim.ScanForValidity(Tran.ItemCode);
}
This allowed a function from one class to get data from another. In VC++ I find a wall between classes that I can't get through. I can do whatever I want within the various functions of the same class, but can't get the data out of the class.
Since I had main(), I never needed to reference a function of classABC from a function of classXYZ.
If I write function SetSomething() for a class, I cannot reference the SetSomething() function in a function of any other class. So, I can't "set" anything.
Likewise, if I write a function GetSomething() for a class, I can't reference the GetSomething() function in a function of any other class. So, I can't "get" anything.
I am defing all my classes in the same .h header file. I am coding the all the functions in the same .cpp file.
Since VC++ works so well for so many people, I conclude the problem is with me. Suggestions?
|
|
|
|
|
Progress. I created an instance of my Orders class within the declaration of the CDialog derived class. This lets the CDialog derived class deal with the Orders class functions and variables. (I think this is what Rudolf suggesed, but it took a while to comprehend.)
//HeadClassDlg.h
class CHeadClassDlg : public CDialog
{
...
...
...
Orders Buy; // <----This is what worked
};
Now functions in HeadClassDlg can access variables and functions from the Buy object of class Orders.
Thanks for the help.
|
|
|
|
|
I'm trying to understand what I'm doing right now from a high level point of view. Fitting it in to a formal design pattern often helps me formalize my thinking. This hunk of code though is eluding my classifying abilities and I'd like to hear your opinions.
My networking API works on the premise of messages as the base component. The next layer above that is sort of like a request-response system. For example you request the server version number, perhaps to ensure messages are handled the same way at the server\client ends, and receive a concrete type, say a pair of integers.
This is almost similar to to the command pattern for the response part, where the network server class transforms a packet back in to a class. When the response to a request has come back I need something similar to a callback to let the requestor get it's data.
To represent that, I need to call in to something (my app is multithreaded). What I devised was a series of standard response types, Integer response, string response, VectorOfStrings response, etc. The trouble with this model is that I'll have to keep creating response types to all the different scenarios, VectorOfInts etc, etc...
Is there a better way?
|
|
|
|
|
I'm working on something similar to this. I started by looking at various Socket and MOM libararies here on CP and elsewhere. Two in particular are MQ4CPP and Muscle. In the end these were not what I wanted, but they helped provide a better understanding of sockets, messaging etc.
So I've written my own simple implementation. I've not used the callback approach as I have a simple protocol which can be handled in a procedural fashion. In order to handle the various types of data (int, string, file etc) I've used the CDiggins any class which is here on CP. This has kept my interface into the socket code simple as it only uses any's. An any is a variant that can hold anything.
There is also an article here on CP that uses a state machine approach, which you may find of itnerest.
I've got all this stuff in Surfulater, so let me know if you need any links. HTH
|
|
|
|
|
Hi,
I have an application that creates a word document with couple of lines of text. I do not use MFC. Does anyone know how can I change my font (to Courier New).
I add text like that sp setting the font should work similarly:
szFunction = OLESTR("TypeText");
hr = pDispSel->GetIDsOfNames(IID_NULL, &szFunction, 1,
LOCALE_USER_DEFAULT, &dispid_TypeText);
then I set text and...
hr = pDispSel->Invoke (dispid_TypeText, IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
&dpTypeText, NULL, NULL, NULL);
Thanks a lot!!
|
|
|
|