|
There isn't any way to do this. printf and routines like it are VERY dependent on the format string telling the routine exactly what to expect in the calling arguments. Thus, if your calling arguments don't match the format string, you get a crash.
In other cases, you might use a NULL value to terminate the argument list. Or you could even have a count at the start of the argument list. It is really up to you exactly what you want to do.
The only thing you have to remember is that there is no way to get the real number of arguments on the stack amd you can't tell what types of arguments were placed on the stack.
Tim Smith
"Programmers are always surrounded by complexity; we can not avoid it... If our basic tool, the language in which we design and code our programs, is also complicated, the language itself becomes part of the problem rather that part of the solution."
Hoare - 1980 ACM Turing Award Lecture
|
|
|
|
|
According to the spec for var args:
It is upto the calling routine to specify in some manner how many arguments there are, since it is not always possible to determine the number of arguments from the stack frame
Best way would be to pass a parameter before the var args specifying how many arguments are found or, like sprintf, just trawl through the arguments and hope they are all there. Neither are particulary robust...
|
|
|
|
|
How can I get my IP (dotted format) programmatically (I'm using Dialup Modem if this matters, <ye ye,="" don't="" laugh="">)?
--BlackSmith--
"With the help of all mighty", 2001, Me.
|
|
|
|
|
gethostname()
bibamus, edamus, cras moriemur [eat, drink, for tomorrow we die]
|
|
|
|
|
gethostname() retrieves my machine/username/(watever...)
I need my IP number (255.23.01.121...) when I'm connected to the INET,
the one appears in ipconfig command under IP Address section.
I hope my Q is clearer now .
10X.
--BlackSmith--
"With the help of all mighty", 2001, Me.
|
|
|
|
|
There may well be some nice Win32 functions, but using the Unix socket functions:
struct hostent *ent = gethostbyname (gethostname ());
struct in_addr *in = (struct in_addr *)ent->h_addr_list[0];
printf ("My host IP is %s\n", inet_ntoa (*in));
Very messy I know, and with a distinct lack of error checking
|
|
|
|
|
i don't know how to get it in c++ under windows, but i know in java it is very easy, if help, i will post code for u.
cheers
includeh10
|
|
|
|
|
Hi,
I am trying to receive a HWND_BROADCAST message within an ATL application. I have tried:
1) Adding "ON_REGISTERED_MESSAGE(WM_CFM, OnMyMessage)" to the MessageMap but that doesn't appear to work in a ATL project.
2) I have tried overriding DefWindowProc() and ProcessWindowsMessage, but they are never called.
Can anyone offer me any advice?
Cheers
Richard
|
|
|
|
|
I assume that you have called RegisterWindowsMessage in both the sending and receiving applications.
Happy programming!!
|
|
|
|
|
I saw sample code using sockets and, in the client application, before calling connect there was a bind call, apparently doing nothing.
Was it really necessary?
rechi
|
|
|
|
|
It depends. The client might have wanted to bind to a specific port for some reason. If the sockaddr structure was given a number other than 0 then the client wanted to use a specific port on its end.
bibamus, edamus, cras moriemur [eat, drink, for tomorrow we die]
|
|
|
|
|
TCP:
Server - needs a bind before listen
Client - no bind needed
UDP:
Server and Client - if You use bind You will be able to use send and recv, but You might also use sendto and recvfrom. In that case bind is not needed.
Railgun is like a Gilette Mach 3 - it does the job with one, easy stroke.
|
|
|
|
|
AAAaahhh. My mistake, sorry.
As for TCP it's all true, but as for UDP:
Client - bind is not needed and You can use connect function with send/recv or sendto/recvfrom without connect
Server - bind is needed to specify the address and port
Uh, it's been a long time since i've used sockets. Sorry again, and sorry in advance if I made any more mistakes
Railgun is like a Gilette Mach 3 - it does the job with one, easy stroke.
|
|
|
|
|
Thanx both of you for your efforts!
rechi
|
|
|
|
|
Hi,
I have a need to move a file from one folder to another. It is a .bmp file. How do I do this from within my application.
Thanks
Regards
Ruca
|
|
|
|
|
Use MoveFile
BOOL MoveFile(
LPCTSTR lpExistingFileName, // file name
LPCTSTR lpNewFileName // new file name
);
|
|
|
|
|
I am new to VC++. Can you tell me how to go about learning VC++.
Best Regards
Venkatraman Kalyanam
Chennai - India
You are not an idiot till you open your lips (Anonymous)
|
|
|
|
|
Well, I'm sure you know this but I would suggest buying a beginners book and going through that. They normally explain the Development Environment as well as teach you some c++ and even object oriented programming.
I started with this book: "Microsoft Visual C++ 5: No Experience Required"
- by Steven Holzner.
This is a basic book with examples. Serves to show you how things are done in Visual C++ and what can be done. Not the best book, but simple enough.
I don't know what to suggest for .Net as I have not bought any books myself. And am still working on Visual C++ 6.0.
Of course if you haven't done any coding then you will have to buy a book on programming in general.
Best of luck
Ruca
|
|
|
|
|
The thing is i know how to write a Win32 dll or a ATL component. But i want to know more about MFC and other inner concepts of VC++
Best Regards
Venkatraman Kalyanam
Chennai - India
You are not an idiot till you open your lips (Anonymous)
|
|
|
|
|
www.codeproject.com
www.codeguru.com
www.maxcode.com
http://www.funducode.com/
helps u alot to learn vC++
windows programming by petzrold
MFC programming by Jeff prousise
MFC programming by Krughlinski
these are the books from Microsoft press
and they are good
as u are beginner
take VC++ programming by yp kanethkar(Indian author)
|
|
|
|
|
How to convert from unsigned short[30] to const char *
WCHAR to const char *
|
|
|
|
|
LPCWSTR sUnsignedShort = L"One string";
LPCSTR sAnsiChar = NULL;
USES_CONVERSION;
sAnsiChar = OLE2CA (sUnsignedShort);
|
|
|
|
|
// there are some code maybe useful for you
//WCHAR *,LPOLESTR and LPWSTR are same thing in win32(without UNICODE defined)
//TCHAR to WCHAR
TCHAR szModule[_MAX_PATH];
GetModuleFileName(NULL, szModule, _MAX_PATH);
USES_CONVERSION;
LPOLESTR pszModule = T2OLE(szModule);
//WCHAR to TCHAR
USES_CONVERSION;
LPOLESTR lpOleStr;
StringFromCLSID(clsid, &lpOleStr);
LPTSTR lpsz = OLE2T(lpOleStr);
CoTaskMemFree(lpOleStr);
|
|
|
|
|
I drived a class from CObject;all like this;
class CPerson :public CObject
{
public:
CPerson();
CPerson(CPerson &person);
CPerson & operator =(CPerson person);
CString m_strName;
};
CPerson::CPerson()
{
m_strNmae=_T("");
}
CPerson::CPerson(CPerson &person)
{
m_strName=person.m_strName;
}
CPerson &CPerson::operator =(CPerson &person)
{
m_strName=person.m_strName;
return *this;
}
but erro happed in compling ;the message is:
d:\microsoft visual studio\vc98\mfc\include\afxtempl.h(255) : error C2558: class 'CPerson' : no copy constructor available
d:\microsoft visual studio\vc98\mfc\include\afxtempl.h(1566) : while compiling class-template member function 'class CPerson __thiscall CArray<class CPerson,class CPerson &>::GetAt(int) const'
Error executing cl.exe.
who can tel me where is the erros!
I am Made!
|
|
|
|
|
A copy constructor is defined to get a const reference, so you have to modify the param list of your copy constructor and your operator =. It should look like (const CPerson& person) .
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|