|
Hi,
I have a CArray - m_array < STRUCT1, STRUCT1 > and I want put his to the CMap < DWORD, DWORD, m_array, m_array >. How to make this?
Best regards,
Eugene Pustovoyt
|
|
|
|
|
The simple answer is you can't, not directly. CArray does not have a copy constructor or assignment operator, so it won't work. There are a couple of workarounds however.
1. Make a class that has the array as a member, and define copy constructors and assignment operators that copy the array elements.
2. Derive a class from CArray and implement the copy constructor and assignment operator, and use this class with the map.
I would choose the second option - it is still a CArray, rather than having to go through another class.
Hope this helps,
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Thanks.
Best regards,
Eugene Pustovoyt
|
|
|
|
|
You're welcome
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Another option (the MFC way) is to use the MFC collection classes, which can be nested this way. EX:
CMapWordToOb oMap;
CObArray *pArray = new CObArray;
pArray->Add(..);
oMap.SetAt(KeyValue,pArray);
The bonus of doing this in this way is that it is directly Serializable.
onwards and upwards...
|
|
|
|
|
Yes, but he said he wanted to put a CArray in a CMap, not a CArray* (yes, I know it's pedantic )
basementman wrote:
The bonus of doing this in this way is that it is directly Serializable.
Good point. I didn't think of that
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Hi all,
I am in desperate need to know the dynamic IP allocated to a user when he browses by the ISP, also I want to know the Browser Language..can anyone show me some pointers or ideas or tutorials to do this..any sort of help is highly appreciated...Thanks a lot in advance...
Himanshu
|
|
|
|
|
Here is a code snippet that may be called more than once. The first time will return how many NET I/O addresses are available, a second call may nominate which of the available IP addresses to return. Hope this helps...
cheers
WillB
//*****************************************************************
//** **
//** **
//** **
//** G E T H O S T N A M E **
//** **
//** **
//** **
//*****************************************************************
int MNF_GetHostIPAddress( CString & rszHostName,
CString &rszHostIPAddress,
int nIPSelection)
{
int nIPCount = 0;
in_addr **papIPAddressList;
HOSTENT *ptHostEnt = NULL;
rszHostIPAddress = "";
// ---> ----------------------- <---
// ---> Discover IP address(es) <---
// ---> ----------------------- <---
ptHostEnt = gethostbyname( rszHostName );
if ( ptHostEnt != NULL )
{
papIPAddressList = (in_addr **)&ptHostEnt->h_addr_list[ 0 ];
// ---> ----------------------- <---
// ---> Count the IP Addressess <---
// ---> ----------------------- <---
while ( papIPAddressList[ nIPCount ] != NULL )
{
nIPCount++;
}
if ( nIPSelection < nIPCount )
{
rszHostIPAddress = inet_ntoa( *papIPAddressList[ IPSelection ] );
}
}
return nIPCount;
}
|
|
|
|
|
Thanks for the code snippet..but I guess it doesnt work properly, as we will have to pass some arguments..I dont want to pass any prguments into it and want to know the IP address of the machine assigned by the ISP. Not the local IP I can do that. How to get the ISP provided IP. Please help.Any help or pointers are appreciated..
Thanks in advance.
Himanshu
|
|
|
|
|
The "IP Helper API" is the keyword you're looking for and here's a snippet of the code that I've written to gather all IP addresses assigned to the system:
ULONG adpsize = 32768;
void* adpinf = malloc(adpsize);
if (GetAdaptersInfo((PIP_ADAPTER_INFO) adpinf, &adpsize) == ERROR_SUCCESS)
{
PIP_ADAPTER_INFO pip = (PIP_ADAPTER_INFO) adpinf;
while (pip)
{
PIP_ADDR_STRING ips = &pip->IpAddressList;
while (ips)
{
ips = ips->Next;
}
pip = pip->Next;
}
}
free(adpinf);
Regarding your question about the language of the OS you can use GetSystemDefaultLangID from the Win32 API, if I understood your question correctly.
|
|
|
|
|
Thanks for the language thing...can you please tell the dependencies etc..i am unable to compile ur code..i used iphlpi.h and its lib file in link..but still it is not compiling and can you message the IPS issued from this code..I shall be highly obliged if u can revert back asap..
thanks in advance..
Himanshu
|
|
|
|
|
The only dependency is iphlpapi.lib which comes with Platform SDK I guess, you should download & install it if you haven't already done so. If it gives a linker error then that's the case, if not could you please paste the error lines?
When I run this on my computer I get two IP addresses, cause I have two ethernet adapters: one for my LAN and one for my cable connection to the Internet. Back to your question, a dialup adapter is a virtual adapter and thus if the ISP has assigned an IP to your computer via DHCP, you should get it in that loop as well. In your case, if the host computer has more than one IP address such as mine, you should have your own way of differentiating it from the other IP addresses, such as checking for the type of the adapter, looking for a name etc...
Sorry for the late response, I've been sleeping all day
|
|
|
|
|
Hi,
Thanks for ur sooner reply..I dont have any errors now..but I cannot understand the parameters to be passed..CString& rszHostName,CString& rszHostIPAddress, int nIPSelection..please guide.and reply soon..I shall be waiting for ur response. Thanks a ton in advance..
Himanshu
|
|
|
|
|
Hi Himanshu,
Sorry but I really don't think that I do understand. Weren't you asking for the IP address of the local computer? Now say that's the rszHostIPAddress parameter. What are the other two? You've mentioned above you needed a function which receives no parameters, now you want to pass parameters to it?
The method I've described above let's you get the IP addresses assigned to a computer, note that whilst a computer has a single hostname, it can have many IP addresses. And that about nIPSelection, I really don't understand, sorry...
|
|
|
|
|
I am running VC++ Vn 6.0 SP5 and am writing a program using multiple threads with CSockets. I am having problems i.e.
Popup Dialog with:
Microsoft Visual C++ Debug Library
Debug Assertion Failed!
File: sockcore.cpp
Line: 567
This type of problem is documented on MSDN in an article "Q193101" acknowledging a bug in the static library. MSDN SP5 has a fix(?) for this and suggests adding "AfxSockInit()" to each each thread that uses sockets. I have done this and I am not getting assertions in the Release exe but I am still getting them in the debug version.
Do I need new debug libraries, or should I just ignore the assertions - this is a "pita".
suggestions welcome
whybotha69@hotmail.com
// the last C bug
if (missilesDetected());
LaunchCounterAttack();
|
|
|
|
|
Debug assertions are used in the MFC library to indicate when the programmer has used the library in the wrong way, ie. you are doing something wrong. Run your app in debug mode and when the assertion comes up, hit debug, and try to trace what is actually causing the error. 99.9% of the time it's because you have made a mistake in your program and are using the library the wrong way.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Thanks for the comment, but I did all that and found the (mentioned) MSDN article. It was after exhausting all these avenues that I turned here !!
|
|
|
|
|
No problem, just checking the obvious first. At least somebody does the right thing
What line was the error on? I've never used the MFC socket classes - I prefer to use the Winsock APIs directly (I've done most of my sockets programming under Unix/Linux ). I might be able to pick out some problems if you can tell me the file/line number though.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Thanks Ryans,
File: sockcore.cpp
Line: 567
It was in the original post (I stepped through the code) and the problem appears to be in ...\SOCKCORE.CPP starting at line 563 (the Line: 567 CAsyncSocket::FromHandle(...) part).
#ifdef _DEBUG
void CAsyncSocket::AssertValid() const
{
CObject::AssertValid();
ASSERT(m_hSocket == INVALID_SOCKET || CAsyncSocket::FromHandle(m_hSocket) != NULL);
}
Any news may be good news !!
I am happy to send the Client and the server projects to anyone who may be able to assist!!
cheers Will Beattie
|
|
|
|
|
It certainly looks like an internal library error. MFC maintains a map of socket handles to CAsyncSocket/CSocket objects. What this error is saying is that your socket handle is not mapped to a socket CAsyncSocket or CSocket object. If you're only using MFC socket classes, then it must be, and it's not being placed into the map properly. You might like to trace through from when you create (or accept, if it's an accepted socket) the socket, and see if it's being placed into the socket map.
Other than this, I can't help any more.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
If this assertion fires randomly, i.e. it fires sometimes and especially when the connection is being or is closed, then please read further. Otherwise just ignore me.
Actually this is an internal error and I don't think you're doing anything wrong at all. If it works fine in the release build, than that's it. I believe this is caused by the bad habit of abortive closing of the socket. The CAsyncSocket is a cumbersome implementation of winsock (and CSocket is much much worse) in which it uses hidden windows to receive asynchronous notifications and sometimes fails badly to handle the case, especially in abortive closures as I've mentioned. My assumption is that some window message(s) will get received after the socket has been closed and this assertion fires. Eventually it's not only that assertion on Line 567, there are many more you could face.
Networking is chaotic due to the nature of connectivity and it's almost impossible to reproduce the problem, so that's why this assertion sometimes fires and sometimes does not and that's why I never succeeded in finding out the reason of the CAsyncSocket asserts. Though I'm not getting them that frequently (by the time of writing this I've noticed, I haven't got one since a month! I must have done something..) I've given up. Just blame it on Microsoft and everything's fine again.
Btw. CSocket and CAsyncSocket should really really be derived from CWnd. So, bad design + verygoodgodlikewhatever programming -> bad implementation.
|
|
|
|
|
How is it possible to put a bimap on a button??
Pls help
San
|
|
|
|
|
Definitely! One solution is to add the bitmap into project resources. Load it and the button via SetBitmap().
Kuphryn
|
|
|
|
|
|
How can I use CString format the string like "12,123.23" thanks
|
|
|
|