|
perhaps posting your code would be a start. Why do you think it's in an infinite loop ? How do you deallocate the array ? When do you ?
See how much easier this will be when you post the code ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I am writing an application that open multiple sockets to a server. A number of threads (about 10) are each given a pointer to functions previously resolved from a DLL that handle the sockets.
My code works fine for 1-4 threads, but any more than that and WSAEnumNetworkEvents() returns a socket error. My code is in a DLL and have two global variables SOCKET* pSocket and WSAEVENT* hEvent.
I know that multiple threads cannot safely access the same value, so I made them pointers and each time a thread calls this function the new operator allocates memory to the value. Is this ok?
The code I use for socket connection is show below:
WORD wVersionRequested = MAKEWORD(2,0);
WSADATA wsaData;
int nRet;
nRet = WSAStartup(wVersionRequested, &wsaData);
if(nRet) {
WSACleanup();
return -1;
}
if(wsaData.wVersion != wVersionRequested) {
WSACleanup();
return -1;
}
LPHOSTENT lpHostEntry;
lpHostEntry = gethostbyname(lpServerName);
if(lpHostEntry == NULL) {
WSACleanup();
return -1;
}
SOCKADDR_IN sa;
sa.sin_family = AF_INET;
sa.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
sa.sin_port = htons(nPort);
pSocket = new SOCKET;
*pSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(*pSocket == INVALID_SOCKET) {
WSACleanup();
return -1;
}
hEvent = new WSAEVENT;
*hEvent = WSACreateEvent();
if(*hEvent == WSA_INVALID_EVENT) {
AfxMessageBox("WSACreateEvent()");
closesocket(*pSocket);
WSACleanup();
return -1;
}
nRet = WSAEventSelect(*pSocket, *hEvent, FD_READ|FD_CONNECT|FD_CLOSE);
if(nRet == SOCKET_ERROR) {
AfxMessageBox("EventSelect()");
closesocket(*pSocket);
WSACloseEvent(*hEvent);
WSACleanup();
return -1;
}
nRet = connect(*pSocket, (LPSOCKADDR)&sa, sizeof(SOCKADDR_IN));
if(nRet == SOCKET_ERROR) {
nRet = WSAGetLastError();
if(nRet == WSAEWOULDBLOCK) {
}
else {
closesocket(*pSocket);
WSACloseEvent(*hEvent);
WSACleanup();
return -1;
}
}
WSANETWORKEVENTS events;
while(1) {
DWORD dwRet;
dwRet = WSAWaitForMultipleEvents(1,
hEvent,
FALSE,
5000,
FALSE);
if (dwRet == WSA_WAIT_TIMEOUT) {
AfxMessageBox("Wait timed out1");
closesocket(*pSocket);
WSACloseEvent(*hEvent);
return -1;
}
nRet = WSAEnumNetworkEvents(*pSocket, *hEvent, &events);
if (nRet == SOCKET_ERROR) {
AfxMessageBox("WSAEnumNetworkEvents()");
closesocket(*pSocket);
WSACloseEvent(*hEvent);
return -1;
}
if (events.lNetworkEvents & FD_CLOSE) {
AfxMessageBox("closing...");
closesocket(*pSocket);
WSACloseEvent(*hEvent);
}
if (events.lNetworkEvents & FD_CONNECT) {
if(events.iErrorCode[FD_CONNECT_BIT]!=0)
return -1;
return 0;
}
}
return 0;
There are 10 types of people in the world
Those who understand binary, and those who don't
|
|
|
|
|
I'm trying to write a console app that I can use to feed in a user name and get back all the machines that user is ucrrently logged into by doing a query to a WINS database. But I can't seem to find any documentation whatsoever about WINS. So any links/examples/wisdom would be welcome. Thanks.
|
|
|
|
|
Anyone??? I think it could be done with the Netbios NCBFINDNAME, but am not sure how to use it. Any help whatsoever would be greatly appreciated. Thanks.
|
|
|
|
|
What is the number (not MACRO because I have VC++ 6 so I dought I have that macro defined anywhere) I would pass to GetSysColor() to retreive the color of an non-active menu item like XP displays for menu items which weren't used recently...
Now unless I was dreaming...cuz I just checked my menus in start menu and they no longer had that difference in color for not very active menu items (i must have changed it and not noticed ) these should be a color index for GetSysColor() which I can use
if not or even better still...does there exist a formula I can apply to say...GetSysColor(COLOR_BTNFACE) which will make it lighter by a certain percentage???
This would be ideal...that way my app will still work in 98 Even though i'm thinking a simple GetSysColor() call with incorrect index wouldn't crash my app...I would still feel better about it
Thanks a bunch
Cheers
I'm drinking triples, seeing double and acting single
|
|
|
|
|
Hi ...
Umm, I didn't get time to test it but I threw this together. I think it's what you want. It'll return a colour based on the colour you supply it and the value of dBrighten and bContrast. These double values are to be between 0 and 1 (0% to 100% divided by 100).
Hope this helps,
Mike
#include <math.h>
.
.
COLORREF LightenColour(COLORREF colour, double dBrighten, double dContrast)
{
const int GREY = 0x7f;
const int m_nContrast = 90;
int nStepB = (int)floor(dBrighten * GREY);
double dStepC = dContrast;
int nColourValue;
nColourValue = GetRValue(colour) + nStepB;
nColourValue = (int)floor((nColourValue - GREY) * dStepC) + GREY;
int nR = (nColourValue < 0x00) ? 0x00 : (nColourValue > 0xff) ? 0xff : nColourValue;
nColourValue = GetGValue(colour) + nStepB;
nColourValue = (int)floor((nColourValue - GREY) * dStepC) + GREY;
int nG = (nColourValue < 0x00) ? 0x00 : (nColourValue > 0xff) ? 0xff : nColourValue;
nColourValue = GetBValue(colour) + nStepB;
nColourValue = (int)floor((nColourValue - GREY) * dStepC) + GREY;
int nB = (nColourValue < 0x00) ? 0x00 : (nColourValue > 0xff) ? 0xff : nColourValue;
return RGB(nR, nG, nB);
};
|
|
|
|
|
Coolness...alot more code than I thought it would take, but still cool
Thank again
I'm drinking triples, seeing double and acting single
|
|
|
|
|
I am calling a modal dialog from a dll. I have a button on my main application that when pressed calls a dialog from the dll. Note I am not saying this approach is correct but it is what I have.
void CHTPCCOREDlg::OnButton1()
{
PLUGIN.m_pPlugin->Initialize();
}
void CPlugin::Initialize()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CPlugin dlg;
dlg.DoModal();
}
Which seems to work fine. Then in the dll when I want to return to the main application I have the following code.
void CPlugin::CheckKeyState() // called from a timer
{
if(IsKeyDown(VK_BACK))
{
Cleanup();
CDialog::OnOK();
}
}
All is fine and dandy the first go around. I start the app. I press the button to call the dll. The dll shows it's dialog as expected. I hit the Backspace key and the plugins dialog closes and all is fine. Well, until the press the button to initialize the plugin for a second time. The app just hangs. It appears that the dialog is attempting to display but it never does. I can then press the backspace key again then a press of the button to init the plugin works again.
Any pointers would be appreciated.
|
|
|
|
|
Check AfxSetResourceHandle() function: It may help...
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
Thanks for the suggestion. I will look at the function you mentioned.
In the mean time I found the problem. I have a function to go full screen.
fs = !fs;
GoFullScreen(this->m_hWnd, fs, &sizerect);
In early stages I had fs defined globally to 0. So the first time thru the function went fullscreen. The second time thru it was being set to not use full screen which I have not tested and which obviously does not work yet.
Thanks for your response.
|
|
|
|
|
Hi everyone!
I need to create a button array that can be resized.
I tought it was easy like in VB but I got a problem. I'm unable to create buttons!
For example, I placed this is my header file :
CButton* myButton;<br />
<br />
int nbButtons;<br />
<br />
void InsertButton(LPCTSTR lpszText);
Then in the implementation file, I've set
void CLinkList::InsertButton(LPCTSTR lpszText)<br />
{<br />
if(nbButtons<1)
myButton=(CButton*)malloc(sizeof(CButton)*(nbButtons+1)); <br />
else
myButton=(CButton*)realloc(myButton, sizeof(CButton)* (nbButtons+1)); <br />
<br />
CRect rect(0,nbButtons*25,60,20);<br />
<br />
myButton[nIndex].Create( lpszText, WS_VISIBLE | WS_CHILD, rect, this, GetDlgCtrlID() );<br />
<br />
nbButtons++;<br />
<br />
}
But I'm not able to create any button. I didn't get any assertion error but it stop within the CButton::Create function. I don't have any idea of what is the problem.
I know that if I create a static array like :
CButton myButton[30];
it works very well...
What's wrong with the way I do, and how can I solve it? Notice that I want my array to be resized because I don't want to hold a "big" static array. And probably because I'm curious to know how it works too!
It will be very appreciated if somebody here could help me!!
Stef
Progamming looks like taking drugs...
I think I did an overdose.
|
|
|
|
|
I just had this problem yesterday (sorta).
Instead I used MFC CArray and the problem I was having was that CButton doesn't have a default copy constructor and I wasn't interested in writting one, so I did what was most obvious
Use CArray like this:
CArray<CButton*, CButton*> m_pButtons;
I'm drinking triples, seeing double and acting single
|
|
|
|
|
Most likely the problem lies in your use of realloc . Simply put, realloc won't work except if the types contained in the array are primitive (integer types, pointers, little more.) The reason is that realloc , when moving to a larger block of memory, copies the original contents as if with memcpy , and this is not guaranteed to work for types which provide their own copy constructors.
My suggestion is that you store pointers to CButton instead of CButton objects. This implies an extra allocation per button:
myButton[nIndex]=new CButton;
myButton[nIndex]->Create(...); and don't forget to delete these objects when done.
Also, do yourself a favor and forget about realloc . C++ provides for instance std::vector which does the work in a far easier way.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
It doesn't work...
It stop at:
myButton[nIndex]=new CButton;
I have declared myButton like this :
CButton** myButton;
Any Idea. I have an headhache so, my brain doesn't work as much as I want !
Progamming looks like taking drugs...
I think I did an overdose.
|
|
|
|
|
I get it!!
I just forgot size the array of CButton pointers...
myButton = new CButton*;<br />
myButton[nIndex] = new CButton;
Now, I just have to find out how to resize it !
Tanks a lot
Stef
Progamming looks like taking drugs...
I think I did an overdose.
|
|
|
|
|
I have a COM class in which I have an ATL collection variable, like this:
CAtlList<StructData> MyList;
Where StructData is a user-defined structure.
Now I want to pass the MyList variable to the constructor of a CDialog class, so that the dialog class can read and write data to the variable.
How should this be done?
I get nothing but error messages while trying, so I need help.
|
|
|
|
|
What is the difference between Win32, Windows API, MFC, ATL, and COM?
Forgive my ignorance I am new to Windows programming.
|
|
|
|
|
SDK API = (Software development kit) Application programming interface (Analogous to CRT in DOS kinda). SDK includes the tools and docs required and API is the standard or the function interfaces.
MFC = Microsoft foundation classes is a framework (Basically a bunch of classes which do what the win32 API does, but more OOP friendly)
WTL/ATL=Windows/Active template library. Basically does what MFC does for windows API, but using template classes instead of C++ classes.
COM/ActiveX = Was an idea M$ had which would allow for code to be modularized (if thats a word ) basically kept in a binary form which any supported language could use (VB, C++, Delphi, etc). In C++ programmers have long since passed around code in source form as C++ classes, however programmers were still still free to mess up code, modify it, etc...not ideal for commercial code your trying to sell. COM objects were designed to fix this, by keeping everything binary...so programmers had to manipulate data members via accessor/mutators like any OO purist would tell you to do. Also you hide the implementation much better than a C++ class...because functions which are meant to be private are not visible to client programmers...only interface functions are(actually it's at programmers discretion).
COM=Component object model...basically it's a standard binary communication mechanism required for code (written in delphi, c/c++, etc) to communicate with ActiveX/COM objects. This gets hard to explain briefly...i'd advise you to read an article or two on the idea/theory behind it...MSDN used to have lots...but i'm not sure if ActiveX/COM is as big of a buzz word as it was a few years ago, since the release of .NET...you'd have to ask someone more familiar with what .NET actually is and does
This is as far as I understand it anyways
I'm drinking triples, seeing double and acting single
|
|
|
|
|
Mine was funnier, even if later. :P
-Blake
|
|
|
|
|
Windows API: The application programming interface (API) exposed by the windows operating system. In Unix terms this would be like the OS system call interface, excepting of course of the fact that the Windows API does everything, rather than having half a dozen different APIs you must code to, like Unix, X, Qt, etc.
Win32: Coined to distinguish between the Windows API exposed by old 16 bit versions of Windows, i.e. Windows 1.0-3.11, and 32 bit versions, i.e. Windows 95-ME and Windows NT 3.1-Windows 2003 Server. Win32 is now a synonym for Windows API since the Win16 API is dead and forgotten.
MFC: Microsoft Foundation Classes - the original application framework that Microsoft first shipped with their C 6.0 compiler. It is old and crufty and designed for C++ without templates or other modern features. It tries hard to force everything into the Model-View-Controller design pattern.
ATL: Active Template Library - named in an era when Microsoft was sticking Active on the front of everything, like ActiveX, ActiveServer, ActiveMovie, ActiveBob. This is a newer library, designed primarily to support writing COM components in C++. It uses the language in a much more modern way than MFC, but doesn't cover nearly the same breadth of functionality. You can bold ATL and MFC together in the same application but it isn't really a great match.
WTL: You missed this one, but it is important. This is a library build on top of ATL that broadens it's scope to make it closer to an application framework. It is much lighter and faster than MFC. It has an amusing history of being supported and then unsupported and then supported by Microsoft.
COM: Component Object Model - This was born as OLE2, but left it's parent in the dust and is the standard binary component specification that virtually all Windows software was based around until .NET arrived on the scene. COM is dead, long live COM.
-Blake
|
|
|
|
|
Thanks
|
|
|
|
|
I am just seeking opinions. It has been more that 15 years since I dealt with these types of issues.
I am looking for a database management tool along the lines of how I vaguely remember LANSA and SIGNON for the AS/400.
Requirements:
1. Supports SEQUEL server, other relational databases nice but not required.
2. Builds Tables and Indexes from models.
3. Provides a front end for defining database triggers.
4. Will generate simple maintenance programs. Add/Delete/Inquire on a per table bases or SQL view.
5. Will provide for an upload process. Let me explain this one. Let’s just say I have a master database, and (standalone) clients periodically (weekly) physically attach to my network. Hopefully the tool would assist in importing changed information from these clients and exporting data to these clients.
Again, I am not asking for your deep analysis, but rather for product suggestions or personal views you may have.
Thank you
|
|
|
|
|
I don't know nothing about C++. I built and addin using VB.NET and got from www.microsoft.com a shim object.
This object has a reference to stdafx.h and stdafx.cpp.
Now I can't compile it, I have an error message that says:
c:\Development\CrossNET\COMAddInShim\stdafx.h(48): error C3506: there is no typelib registered for LIBID '{AC0714F2-3D04-11D1-AE7D-00A0C90F26F4}'
I tried searching the registry to see what this GUID is about, but can't find nothing.
Can someone please help me with this ??
I need to do a deployment tomorrow morning and QA people are waiting for this component to be compiled.
Thanks
Free your mind...
|
|
|
|
|
Perhaps you should register the type library ? DO you *have* the type library ? Know what a type library is ?
I'd suggest that 'there is no typelib registered' would be a good sign that you're not gonna find this GUID in the registry. That's the problem.
Why link to www.microsoft.com but not the object ? Where did you get it ? What is it going to do for you ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
How do I make them disappear...?
I've tried:
cs.dwStyles = ~ WS_VSCROLL;
But it causes the framework to not create a document or something like that...
Any ideas how I can go abouts doing this...?
I'm sure it's a CMDIChildWnd thats causing the scrollbars to appear because when I add scrollbars to embedded view I get double scrollbars...I also have concluded it's CSplitterWnd thats making scrollbars appear...
Thanks again
I'm drinking triples, seeing double and acting single
|
|
|
|