|
Have you tried binding your socket to the specific IP addresses?
|
|
|
|
|
Thanks for going through it.
I did not try to bind the socket with specific IP address.
Also this is not a requirement for me. I will give a try just to verify if it is possible but my intention is to receive data from all the adapter connected to same netwoek(router). Earlier I am using DHCP so that time it was not a problem for me cause all the adapter was getting the same default gateway but now I am switching to static where user can put any IP address with different default gateway.
|
|
|
|
|
Also as I can see the data in wireshark, looks like PC is receiving this data but it is not reaching to application
|
|
|
|
|
You will receive messages on the socket that you have created, which will bind to the first adapter. If you wish to receive on both then you need two sockets one bound to each IP address.
|
|
|
|
|
|
Thanks for your valuable suggestion. I am trying all this, I will update you once I will collect the result.
|
|
|
|
|
Hello everybody,
Currently all my C++ project are on a Windows XP machine. For database connections I’m using ado. In stdafx.h I have lines:
#import "c:\Program Files\Common Files\system\ado\msado15.dll" rename_namespace( "ado" ) rename("EOF", "ADOEOF")
#import "C:\Program Files\Microsoft SQL Server\80\Tools\Binn\Resources\1033\sqldmo.rll" no_namespace
And when it’s required I call
ado::_ConnectionPtr pConn = NULL;
hr = pConn.CreateInstance( __uuidof( ado::Connection ) );
Everything has been working fine.
But now I’m moving all my projects to Windows 7 machine. And it appears, that created .exe files are working fine on Windows 7 machine but on Windows XP ado pointer could not be created.
hr = pConn.CreateInstance( __uuidof( ado::Connection ) );
doesn’t create valid connection object.
Thank you in advance, any suggestions will be appreciated
|
|
|
|
|
|
Dear all:
I try to use global hook with WH_GETMESSAGE, but still failed.
It work only on my application, not global. My code show as below:
#pragma data_seg (".SHARED")
HHOOK g_hPreviousMsgHook = 0;
HINSTANCE g_hInstance = 0;
#pragma data_seg()
#pragma comment(linker, "/SECTION:.SHARED,RWS")
BOOL CSoundDllApp::InitInstance()
{
CWinApp::InitInstance();
g_hInstance = AfxGetInstanceHandle();
return TRUE;
}
BOOL InstallWinHook()
{
BOOL bReturn = TRUE;
g_hPreviousMsgHook = SetWindowsHookEx(WH_GETMESSAGE,
&MsgHookProcedure, g_hInstance, 0);
if(NULL == g_hPreviousMsgHook)
{
bReturn = FALSE;
}
return bReturn;
}
LRESULT CALLBACK MsgHookProcedure(int nCode, WPARAM wParam, LPARAM lParam)
{
if(0 > nCode)
return CallNextHookEx(g_hPreviousMsgHook, nCode,
wParam, lParam);
PMSG data = (PMSG)lParam;
switch(data->message)
{
case WM_POINTERDOWN:
Beep(0x7fff, 1000);
break;
}
return CallNextHookEx(g_hPreviousMouseHook, nCode, wParam,
lParam);
}
I set 0 into last parameter of setWindowsHookEx api, but it seem like not work.
Could someone tell me where's wrong, please?
Thanks for your help, Victor
|
|
|
|
|
|
Dear Richard:
It mean I just hook message only from application message queue, so I can not get message from anthor place?
When I touch on some applications, it works.
When I touch on desktop, it does not work.
How? Does it mean the touch message on desktop not exist in application message queue?
Thanks for your help, Victor
|
|
|
|
|
Sorry, my original message was incorrect (the MSDN description lacks clarity). This should capture all messages, not just those directed to your application.
|
|
|
|
|
Recently I want to find a general solution for std::wcout so that it can print out all unicode strings. but, after poking around on google, i can't find useful. I'm stuck here, anybody can help me?
_setmode(_fileno(stdout), _O_U16TEXT); won't work as expected.
Here is my current code snippet:
auto previousMode = _setmode(_fileno(stdout), _O_U16TEXT);
std::wifstream wifs;
wifs.imbue(std::locale(wifs.getloc(), new std::codecvt_utf16<wchar_t, 0x10ffff,
std::codecvt_mode(std::little_endian | std::consume_header)>));
wifs.open(L"F:\\重要网址.txt", std::ios_base::binary);
std::wstring line;
std::getline(wifs, line);
wcout << line << endl;
wifs.close();
wcout << endl;
cout << "∦" << endl;
std::wofstream wofs;
wofs.imbue(std::locale(wifs.getloc(), new std::codecvt_utf16<wchar_t, 0x10ffff,
std::codecvt_mode(std::little_endian | std::consume_header)>));
wofs.open(L"F:\\iMoney.txt", std::ios_base::binary | std::ios_base::ate);
wofs << line << endl;
wofs.close();
_setmode(_fileno(stdout), previousMode);
and here is some symbols to test your slution before post here:
∀, ∁, ∂, ∅, ∰, ∵, ∺, ⊙, ⋾, ⋻, ⋱, ⋭, ⋣, ⋧
Arabic: لطيفة الطقس اليوم
modified 26-Mar-14 6:16am.
|
|
|
|
|
int i = 0;
statement 1: if( i == 0 )
statement 2: if( !i )
Although the speed does not matters in this case, but I want to know the way above 2 statements are evaluated.
|
|
|
|
|
It depends on the compiler and the optimization options.
But in this simple case the generated code should be identical. You can check this by specifying a compiler option to generate assembly code (e.g. /Fas with Microsoft compilers) and compare the generated code.
|
|
|
|
|
I agree with you!
In general, two cases are identical!
|
|
|
|
|
You don't need to care; write readable code, the compiler will be more than sufficient to optimize it.
They will be compile to the same thing.
I'd rather be phishing!
|
|
|
|
|
I think the first one is faster.
because, the in second
- variable first ! converted
- the newly converted variable is converted to 1/0 for if statement
but in first-
-the == operator check bit wise datas of 2 numbers, if matched 1/if not 0.
so i think the first one is faster. Whats your view..
|
|
|
|
|
THERE IS NO DIFFERENCE.
For such simple code, the compiler will generate the same code.
compile and generate the assembly code for both versions, and you will see that the code is the same.
(testes with debug version on VS2012).
I'd rather be phishing!
|
|
|
|
|
shaktikanta wrote: I think the first one is faster.
The compiler need do nothing more than test for zero which the target CPU almost certainly has a single opcode for.
|
|
|
|
|
The second one is faster to type.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Entropy isn't what it used to.
|
|
|
|
|
With something this trivial, it doesn't matter. If you want to write fast code, there are a ton of other bottlenecks that are more important than this.
|
|
|
|
|
Statement 2 should be faster.
- no need to do parsing and comparison, just go to memory to negate, and see if it's above 0 or not.
- compiler can generate machine code that would take less clock circles to execute the if() statement
The speed differences between the 2 statements are negligible,
- but statement 1 reads better, easier to understand and for better documentation.
|
|
|
|
|
ptse wrote: Statement 2 should be faster. They will both be the same; each being a machine code instruction that tests for zero.
|
|
|
|
|
Reposting as thread has grown
#include <<windows.h>> // remove extra angle bracket for compilation
#include <<tchar.h>>
#include <<stdio.h>>
#include <<strsafe.h>>
void FreeMemory(char** myArray, int row);
void FileCountInDir(const TCHAR* dirpath, int * filescount, int* filesize);
void FindFilesInDirectory(const TCHAR* dirpath, char** filelist);
int _tmain(int argc, TCHAR *argv[])
{
int i =0;
TCHAR szDirpath[MAX_PATH];
//TCHAR Filelist[100][MAX_PATH];
char ** Filelist;
int iFileCountInFolder=0;
int iFileSize = 0;
_tcscpy(szDirpath,_T("C:\\BMPread_W\\TransitionEffects\\Images"));
FileCountInDir(szDirpath,&iFileCountInFolder,&iFileSize);
Filelist = (char**)malloc(iFileCountInFolder * sizeof(char *));
if(Filelist == NULL)
{
fprintf(stderr, "out of memory\n");
return 0;
}
for(i = 0; i < iFileCountInFolder; i++)
{
Filelist[i] = (char*)malloc((iFileSize * sizeof(char))+1);
if(Filelist[i] == NULL)
{
fprintf(stderr, "out of memory\n");
return 0;
}
}
FindFilesInDirectory(szDirpath, Filelist);
for(i =0;i 0)|| ((*filesize) < _tcslen(ffd.cFileName)))
{
(*filesize) = _tcslen(ffd.cFileName);
}
}
}
while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
}
void FreeMemory(char** myArray, int row)
{
int i;
if(myArray != NULL)
{
for (i = 0; i < row; i++){
free (myArray[i]);
}
}
|
|
|
|