|
I've got a custom control class that derives from CStatic that should handle WM_RBUTTONUP within its code. unfortunately this message is always redirected to the parent window (a CDialog). What can i do?
Don't try it, just do it!
|
|
|
|
|
Just a guess here but does your static maybe have the SS_NOTIFY style set? If yes then try removing it.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Ah thx, I found it. When SS_NOTIFY isn't set the static control doesn't answer WM_NCHITTEST with HTCLIENT so the messages go to the parent window.
Don't try it, just do it!
|
|
|
|
|
MFC, STUDIO 2008
Help me, please alignment dialog window after
it appear on screen to right side of screen.
Thank you.
|
|
|
|
|
You can use MoveWindow() or SetWindowPos() for this.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Greetings!
I want to enumerate all devices connected to a USB port on my PDA (it`s USB Host and I connect 1 memory stick)
I have a problem enumerating the devices connected to the USB port, which is the very first step.
I get a "0" return when calling the function, even if there is a memory stick attached, which works in the Operating system.
This approach is the classical one, where you ask for device info in order to open a connection.
Here you can find the VC++ 8.0 project for testing pourposes, I have commented the unnecesary code, what`s left is VERY simple.
http://rapidshare.com/files/242608616/USBXpress2_MFC.rar.html[^]
I`m surprised it doesn`t work and I have no idea what's the problem... Can you give me a hint ?
In order to run the application on the smart device itself, you must add the file "SIUSBXP_LIB.dll" to the WINDOWS directory. If you don`t want to do this, I'll tell you what happens:
In USBXpress2_MFCDlg.cpp, the call on line 103 returns 0 (no devices) instead of anything else.
I have tested a memory stick that is being accessed by the Operating System, but this application fails to access it.
Again, the call is very simple...
The SIUSBXP_LIB.lib (and .dll) files are downloaded from the Sylicon Laboratories site, I`m using their files to make a connection between my PDA and my device.
The download link for the project:
Thanks for any possible help!
Vlad
|
|
|
|
|
You might try posting here the exact code that has the problem.
I don't think anybody is going to go download your project and debug it themselves.
Please make your question specific.
|
|
|
|
|
Ok, I`ll try to create the context here. It`s hard to do that, because every function or a parameter is a typedef of a typedef... etc... anyway:
The line that makes me problems: (code in my .cpp file)
DWORD numDevices = 0;
SI_GetNumDevices(&numDevices);
This piece of code returns 0 (the function SI_GetNumDevices does not affect it's value)
Now, this doesn`t tell us anything, therefore:
Definition of SI_GetNumDevices: (in the file header it comes with the dll)
typedefs/defines:
#define SI_USB_XP_API __declspec(dllimport)<br />
typedef int SI_STATUS;<br />
typedef DWORD far *LPDWORD;<br />
#ifdef __cplusplus
extern "C" {
#endif
SI_USB_XP_API
SI_STATUS WINAPI SI_GetNumDevices(
LPDWORD lpdwNumDevices
);
#ifdef __cplusplus
}
#endif
When I search lpdwNumDevices (find all references) the programming tool reports no references, no definitions, no declarations... ??
I have 0 experience working with exterior dlls and libs, and this piece of code was found in one of the examples it comes with the usb fileset. Therefore, I expect it to be a mistake of mine in setting everything in the right way, as the code is likely to be flawless (in its original state) ...
|
|
|
|
|
I might add that the return value of the SI_GetNumDevices is SI_DEVICE_NOT_FOUND - #define of value 255.
So there must be a problem with the hardware, or how I`m connecting it (libraries I suppose) and not this code...
|
|
|
|
|
<pre> I have a question regarding sockets. I am trying to write two programs that will establish connection between each other to send and receive massages. One program sets connection the code is the following:
WSADATA WsaData;
int err = WSAStartup (0x0101, &WsaData);
s = socket(AF_INET,SOCK_STREAM,0);
fer<<"socket error code="<<WSAGetLastError()<<endl;
SOCKADDR_IN anAddr;
anAddr.sin_family = AF_INET;
if (!cm.onemach)
anAddr.sin_port = htons(tcomp->m_port);
else
anAddr.sin_port = htons(1026);
if (!cm.onemach)
anAddr.sin_addr.S_un.S_addr = inet_addr(tcomp->m_ipadr);
else
anAddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
UINT TimeLimit=t;
BOOL connected;
if (connect(s, (struct sockaddr *)&anAddr, sizeof(struct sockaddr))==0)
connected=TRUE;
else
connected=FALSE;
fer<<"connecting error code="<<WSAGetLastError()<<endl;
if (!connected)
return FALSE;
{
err=send(s,sendMessage,strlen(sendMessage),0);
if (err!=0)
{
fer<<"sending error code="<<WSAGetLastError()<<endl;
}
}
And the other accepts connection:
WSADATA wsaData;
int wsaret=WSAStartup(0x0101,&wsaData);
if (wsaret == SOCKET_ERROR) AfxMessageBox("error");
while (flag)
{
servr= socket(AF_INET,SOCK_STREAM,0);
if (servr == INVALID_SOCKET)
{
flag=TRUE;
fer<<"getting message/ creating error code="<<WSAGetLastError()<<endl;
}
else
flag=FALSE;
}
anAddr.sin_family = AF_INET;
anAddr.sin_port = htons(1026);
anAddr.sin_addr.s_addr = INADDR_ANY;
err=-1;
while (err==-1)
{
err=bind( servr, (LPSOCKADDR)&anAddr, sizeof(anAddr) );
if (err!=0)
{
fer<<"binding error code="<<WSAGetLastError()<<endl;
Sleep(1000);
}
}
err=-1;
while (err!=0)
{
err = listen( servr, SOMAXCONN); //SOMAXCONN defined as 5
if (err!=0)
{
fer<<"listening error code="<<WSAGetLastError()<<endl;
Sleep(500);
}
}
SOCKADDR_IN from;
int fromlen=sizeof(from);
fer<<"before accepting error code="<<WSAGetLastError()<<endl;
//gets the address and port of remote/distant comp.
Recv=accept(servr,(struct sockaddr*)&from, &fromlen);//waits for not defined time
fer<<"accepting error code="<<WSAGetLastError()<<endl;
Last time, when I put the question I have been suggested to get WSAGetLastError(). Now I am trying this way and again the program sometimes works correct and sometimes doesn’t work and gives error 10061: Connection refused.
No connection could be made because the target computer actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host—that is, one with no server application running.
Even so the second program waits on accept function the connection is not established. I will appreciate it greatly if anyone can tell me where the error comes or what can be the reason that sometimes it works and sometimes – no, can it be something with socket options or AF_INET address family. Thanks in advance.
|
|
|
|
|
- please don't post and repost again the same question: you may edit the OP.
- use the
<pre> tag to surround code snippets, for instance <pre> code here </pre> .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Tuesday, June 9, 2009 9:19 AM
|
|
|
|
|
<pre> I have a question regarding sockets. I am trying to write two programs that will establish connection between each other to send and receive massages. One program sets connection the code is the following:
WSADATA WsaData;
int err = WSAStartup (0x0101, &WsaData);
s = socket(AF_INET,SOCK_STREAM,0);
fer<<"socket error code="<<WSAGetLastError()<<endl;
SOCKADDR_IN anAddr;
anAddr.sin_family = AF_INET;
if (!cm.onemach)
anAddr.sin_port = htons(tcomp->m_port);
else
anAddr.sin_port = htons(1026);
if (!cm.onemach)
anAddr.sin_addr.S_un.S_addr = inet_addr(tcomp->m_ipadr);
else
anAddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
UINT TimeLimit=t;
BOOL connected;
if (connect(s, (struct sockaddr *)&anAddr, sizeof(struct sockaddr))==0)
connected=TRUE;
else
connected=FALSE;
fer<<"connecting error code="<<WSAGetLastError()<<endl;
if (!connected)
return FALSE;
{
err=send(s,sendMessage,strlen(sendMessage),0);
if (err!=0)
{
fer<<"sending error code="<<WSAGetLastError()<<endl;
}
}
And the other accepts connection:
WSADATA wsaData;
int wsaret=WSAStartup(0x0101,&wsaData);
if (wsaret == SOCKET_ERROR) AfxMessageBox("error");
while (flag)
{
servr= socket(AF_INET,SOCK_STREAM,0);
if (servr == INVALID_SOCKET)
{
flag=TRUE;
fer<<"getting message/ creating error code="<<WSAGetLastError()<<endl;
}
else
flag=FALSE;
}
anAddr.sin_family = AF_INET;
anAddr.sin_port = htons(1026);
anAddr.sin_addr.s_addr = INADDR_ANY;
err=-1;
while (err==-1)
{
err=bind( servr, (LPSOCKADDR)&anAddr, sizeof(anAddr) );
if (err!=0)
{
fer<<"binding error code="<<WSAGetLastError()<<endl;
Sleep(1000);
}
}
err=-1;
while (err!=0)
{
err = listen( servr, SOMAXCONN); //SOMAXCONN defined as 5
if (err!=0)
{
fer<<"listening error code="<<WSAGetLastError()<<endl;
Sleep(500);
}
}
SOCKADDR_IN from;
int fromlen=sizeof(from);
fer<<"before accepting error code="<<WSAGetLastError()<<endl;
//gets the address and port of remote/distant comp.
Recv=accept(servr,(struct sockaddr*)&from, &fromlen);//waits for not defined time
fer<<"accepting error code="<<WSAGetLastError()<<endl;
Last time, when I put the question I have been suggested to get WSAGetLastError(). Now I am trying this way and again the program sometimes works correct and sometimes doesn’t work and gives error 10061: Connection refused.
No connection could be made because the target computer actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host—that is, one with no server application running.
Even so the second program waits on accept function the connection is not established. I will appreciate it greatly if anyone can tell me where the error comes or what can be the reason that sometimes it works and sometimes – no, can it be something with socket options or AF_INET address family. Thanks in advance.
|
|
|
|
|
Are you using some tutorial or sample for this? If not you should be. There are a million of them on the web. There have been for like a decade now. Your use of htons to set port numbers is totally unnecessary and suggests that you need to study more about using sockets. One web site that has existed since like 1995 is Sockets.com. You should check it out.
|
|
|
|
|
I have read various statements in this forum saying things like "it's more efficient to x" or "x is inefficient, I'd try y", or the more helpful "x is terribly inefficient, I'd look for a better method."
How do I determine what is efficent/inefficient, or, more specifically, given two algorithms to accomplish a task, how do I determine which is more efficient?
As a relevent example, I have an object whose member vars need to be backed up by a file, and needs to support multiple instances sharing a file (and therefore values); any time the member vars are modified, the file needs to be updated. File access has to be synchronized through IPC.
A first algorithm would be to synchronize file access within the main process, create the object after getting ownership of the sync object, read the file contents after object creation, modify the vars, write to the file, then destroy the object.
A second algorithm would be to have the main process create the object and maintain it through the main process' lifetime, have the IPC synchronization handled within the object whenever the vars are modified.
A third would be to have the main process create and maintain the object, handle synchronization within the main process, and pass a file handle from the main process to the object methods that modify the vars so they can modify the file.
A fourth would be to have the main process create and maintain the object, handle synchronization within the main process, and have the object use a memory-mapped file to maintain the vars.
A fifth would be the same as the fourth, only handling synchronization within the object.
...and I'm sure I could come up with more...
My limited experience has me leaning towards either the second or the fifth as theoretically most-efficient, but how would I go about actually determining this ?
As always, any answers, or suggestions what I should read, are greatly appreciated.
MZR
P.S.
Then, of course, there's also the question of "execution efficiency" (speed) and "memory efficiency." Is the most memory-efficient always the fastest-executing?
|
|
|
|
|
Mike the Red wrote: Then, of course, there's also the question of "execution efficiency" (speed) and "memory efficiency." Is the most memory-efficient always the fastest-executing?
Depends what you mean by 'memory'. If you mean 'program size', then with modern processors, small code can often mean fast code, due to cache effects. If you mean 'data size', well, possibly not. For example, lots of algorithms can be sped up using lookup tables.
As for your specific issue, I'd probably map the backing file and rather than have member variables in the object, have member accessors that read/write from the mapped file. Probably use a mutex for synchronising file writes. I wouldn't bother synchronising the file reads unless you either a) want to read a big thing from the map, or b) need to keep multiple variables values in sync.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for your response, Stuart.
What I meant to refer to by 'memory efficiency' is efficient use of memory in terms of amount used and how memory is allocated and freed.
I don't know that the speed effect would be sufficient to be measured, but, in terms of how memory is used, this:
for (int i =0; i < someNum; i++) {
BOOL b = SomeFunction(i);
if ( b )
}; ..is not as efficient as this:
BOOL b;
for (int i = 0; i < someNum; i++) {
b = SomeFunction(i);
if ( b )
}; ..because b is only declared/allocated once, instead of once per iteration.
|
|
|
|
|
Heh - when it's stack allocation like your example, there is no speed difference whatsoever. Heap allocation? Yes, there will be overhead for memory management, but stack allocation can be considered near enough zero cost, as stack allocation basically consists of decrementing the stack pointer by the desired byte count.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
Mike the Red wrote: How do I determine what is efficent/inefficient, or, more specifically, given two algorithms to accomplish a task, how do I determine which is more efficient?
you have to identify at all the different actions each algorithm takes, how many times each action is performed for a given input, and the relative costs of those actions. then you can see which operations dominate the processing time for each algorithm. knowing that will help you get an idea as to which algorithm is going to do better for a given input. it might turn out that one algorithm is very fast for small input, but is terrible for large input; so you can switch between them.
Mike the Red wrote: Is the most memory-efficient always the fastest-executing?
no. and for reasonable amounts of memory, there's probably very little correlation between memory usage and performance. if using more memory lets you turn an O(N2) algorithm (execution time increases with the square of the input size) into a O(1) algorithm (execution time is constant, regardless of the size of the input), use the memory.
Big O Notation[^]
for example[^]
|
|
|
|
|
I have a question regarding sockets. I am trying to write two programs that will establish connection between each other to send and receive massages. One program sets connection the code is the following:
WSADATA WsaData;
int err = WSAStartup (0x0101, &WsaData);
s = socket(AF_INET,SOCK_STREAM,0);
fer<<"socket error code="<<WSAGetLastError()<<endl;
SOCKADDR_IN anAddr;
anAddr.sin_family = AF_INET;
if (!cm.onemach)
anAddr.sin_port = htons(tcomp->m_port);
else
anAddr.sin_port = htons(1026);
if (!cm.onemach)
anAddr.sin_addr.S_un.S_addr = inet_addr(tcomp->m_ipadr);
else
anAddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
UINT TimeLimit=t;
BOOL connected;
if (connect(s, (struct sockaddr *)&anAddr, sizeof(struct sockaddr))==0)
connected=TRUE;
else
connected=FALSE;
fer<<"connecting error code="<<WSAGetLastError()<<endl;
if (!connected)
return FALSE;
{
err=send(s,sendMessage,strlen(sendMessage),0);
if (err!=0)
{
fer<<"sending error code="<<WSAGetLastError()<<endl;
}
}
And the other accepts connection:
WSADATA wsaData;
int wsaret=WSAStartup(0x0101,&wsaData);
if (wsaret == SOCKET_ERROR) AfxMessageBox("error");
while (flag)
{
servr= socket(AF_INET,SOCK_STREAM,0);
if (servr == INVALID_SOCKET)
{
flag=TRUE;
fer<<"getting message/ creating error code="<<WSAGetLastError()<<endl;
}
else
flag=FALSE;
}
anAddr.sin_family = AF_INET;
anAddr.sin_port = htons(1026);
anAddr.sin_addr.s_addr = INADDR_ANY;
err=-1;
while (err==-1)
{
err=bind( servr, (LPSOCKADDR)&anAddr, sizeof(anAddr) );
if (err!=0)
{
fer<<"binding error code="<<WSAGetLastError()<<endl;
Sleep(1000);
}
}
err=-1;
while (err!=0)
{
err = listen( servr, SOMAXCONN); //SOMAXCONN defined as 5
if (err!=0)
{
fer<<"listening error code="<<WSAGetLastError()<<endl;
Sleep(500);
}
}
SOCKADDR_IN from;
int fromlen=sizeof(from);
fer<<"before accepting error code="<<WSAGetLastError()<<endl;
//gets the address and port of remote/distant comp.
Recv=accept(servr,(struct sockaddr*)&from, &fromlen);//waits for not defined time
fer<<"accepting error code="<<WSAGetLastError()<<endl;
Last time, when I put the question I have been suggested to get WSAGetLastError(). Now I am trying this way and again the program sometimes works correct and sometimes doesn’t work and gives error 10061: Connection refused.
No connection could be made because the target computer actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host—that is, one with no server application running.
Even so the second program waits on accept function the connection is not established. I will appreciate it greatly if anyone can tell me where the error comes or what can be the reason that sometimes it works and sometimes – no, can it be something with socket options or AF_INET address family. Thanks in advance.
|
|
|
|
|
Could you please format properly (use 'code block' button) you code snippets?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
ok, i'll put it again
|
|
|
|
|
It looks like you failed to, please edit...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi,
My system is having two versions of same DLL located under C:\Windows & C:\Windows\System32 folders.
According to LoadLibrary MSDN documentations, the search path to load DLL will consider System32 folder first and then Windows folder. But when I use LoadLibraryA, it default load the DLL from C:\Windows folder. Whereas, when I use LoadLibraryW, it default load the DLL from C:\Windows\System32 folder.
I googled for the difference between LoadLibraryA & LoadLibraryW and found that one is ASCII version whereas other is UNICODE version.
Now my question is, why LoadLibraryA loads DLL from C:\Windows folder and LoadLibraryW load DLL from C:\Windows\System32 folder???
Regards,
Chirag.
|
|
|
|
|
small info from msdn : LoadLibraryA -ANSI and LoadLibraryW - Unicode
ANSI controls, which work on all Win32 operating systems, allow for maximum portability between the various Win32 operating systems. Unicode controls work on only Windows NT (version 3.51 or later), but not on Windows 95 or Windows 98. If portability is your primary concern, ship ANSI controls. If your controls will run only on Windows NT, you can ship Unicode controls. You could also choose to ship both and have your application install the version most appropriate for the user's operating system.
|
|
|
|
|