|
First off... for something like this, I wouldn't use UDP, I would use TCP/IP. There's really no reason to use UDP, which sends datagrams with no built-in error checking, TCP/IP already handles the error checking/handling (i.e. it'll automatically retransmit packets that didn't arrive at their destination correctly). Usually you only want to use UDP when you have something that doesn't require reliability like voice or video (i.e. if you lose a packet here and there it won't really matter, you'll still be able to hear/see the other person).
As far as sending the data, if you're making for the server and client, it's easy, you define the data messages/structures that are being passed between both completely yourself (via what is typically referred to as an API). Usually the packets are made up of binary buffers, within that buffer, you can either have fixed length or variable length data buffers (or packets), the structure of which is completely up to you.
For example, you can specify:
0. first 4-bytes of the buffer define the message type
1. next 4-bytes define a message specification
2. next 4-bytes define the message size
3. so on...
In this scenario, when you receive a packet, first thing you'll do is cast it onto a data structure that is defined by your API. The first portion of the structure would be an int type (picked it because it's 4-bytes in a 32bit system) and it can specify the type of message that is contained in that data packet. The next portion can be a subset of that message and so on.
Search google and CodeProject for client/server examples and see how they defined their messages.
|
|
|
|
|
I have a CListCtrl with the LVS_EX_CHECKBOXES style and I want to limit the number of items that the user can select. I have written the following code but (of course) it gets itself in a loop because in changing the state of an item, it causes OnItemchangingLoadingValues() to be called again.
void CSpecimenLoadingDialog::OnItemchangingLoadingValues(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int nCheckedItems = 0;
for(int i = 0; i < m_loadingVals.GetItemCount(); i++)
{
BOOL bState = ListView_GetCheckState(m_loadingVals.m_hWnd, i);
if(bState)
{
nCheckedItems++;
}
}
if(nCheckedItems == 2)
{
ListView_SetItemState(m_loadingVals.m_hWnd, pNMListView->iItem, FALSE, LVIS_STATEIMAGEMASK);
}
*pResult = 0;
}
What is the correct way to go about doing this? 
|
|
|
|
|
softwaremonkey wrote: because in changing the state of an item, it causes OnItemchangingLoadingValues() to be called again. But the parameters (i.e., state) passed each time are different.
Rather than use a for() loop each time an item's state changes, simply check the state passed and use a counter. Then in OnItemchangingLoadingValues() , you could have something like:
void CSpecimenLoadingDialog::OnItemchangingLoadingValues(NMHDR* pNMHDR, LRESULT* pResult)
{
if (nCheckedItems < 2)
{
if (pNMHDR's new state equals checked)
nCheckedItems++;
else
nCheckedItems--;
}
}
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
You may add a member variable to your class (or a static variable to the handler function) indicating that the handler is called recursive:
private:
m_bIgnoreChgHandling;
CSpecimenLoadingDialog::CSpecimenLoadingDialog()
{
m_bIgnoreChgHandling = false;
}
void CSpecimenLoadingDialog::OnItemchangingLoadingValues(NMHDR* pNMHDR, LRESULT* pResult)
{
if (!m_bIgnoreChgHandling)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int nCheckedItems = 0;
if(nCheckedItems == 2)
{
m_bIgnoreChgHandling = true;
ListView_SetItemState(m_loadingVals.m_hWnd, pNMListView->iItem, FALSE, LVIS_STATEIMAGEMASK);
m_bIgnoreChgHandling = false;
}
}
*pResult = 0;
}
|
|
|
|
|
Clever stuff - thanks 
|
|
|
|
|
Hi,
At work I only have Visual C++ 6.0 this seems like old compiler as everyone is using Visual Studio
I have to automate the importing of data from a .txt file to an EXCEL spreadsheet
I think using OLE is the answer
My question is, is this do-able with Visual C++ 6.0
Thanks
|
|
|
|
|
Excel, at least recent ones, can open a CSV file.
So presuming the txt file isn't already CSV all you would need to do is read it, parse it, then output in in CSV.
|
|
|
|
|
ForNow wrote: My question is, is this do-able with Visual C++ 6.0 See if this gives you any ideas.
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I am using the wizard to set up this app the program will go to the DATA menu selection on the EXCEL spreadsheet and select import external data
My question when using the wizard to set up the project will the selection be ATL COM AppWizard or WIN32 console application
|
|
|
|
|
Visual C++ 6 will do the job just fine.
Steve
|
|
|
|
|
OLE api is Win32/C, and every C compiler (including msvc of VC6) can handle it.
Nuclear launch detected
|
|
|
|
|
Hello once again,I have been working on some project for a while now and I needed to hook a creation of processes,I have that code(hook/detour)
BOOL WINAPI CreateProcH::CreateProcessInternalW ( HANDLE hToken,
LPCWSTR lpApplicationName,
LPWSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCWSTR lpCurrentDirectory,
LPSTARTUPINFOW lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation,
PHANDLE hNewToken
)
clogf("start %x ref: %x",realCreateProcessInternalW,&realCreateProcessInternalW);
BOOL res = FALSE;
res = realCreateProcessInternalW(hToken,lpApplicationName,lpCommandLine,lpProcessAttributes,lpThreadAttributes,bInheritHandles,dwCreationFlags,lpEnvironment,lpCurrentDirectory,lpStartupInfo,lpProcessInformation,hNewToken);
if(res == FALSE)
return res;
Sleep(100);
vector<wchar_t*> ::iterator it;
for(it = pubvPaths.begin(); it < pubvPaths.end(); it++)
{
if(!CDetour::InjectDll(lpProcessInformation->hProcess,*it))
clogf("InjectDll(lpProcessInformation->hProcess,*it) FAILED!");
clogf("Strlen %d Injecting dll: %ls",lstrlenW(*it),*it);
}
clogf("hThread: %d hProcess: %d dwThreadId: %d dwProcessId: %d",lpProcessInformation->hThread,lpProcessInformation->hProcess,lpProcessInformation->dwThreadId,lpProcessInformation->dwProcessId);
return res;
};
LOG:
[Fri Nov 30 20:22:20 2012] CreateProcH::CreateProcessInternalW reported: start 7d843e8 ref: 741285ac
[Fri Nov 30 20:22:20 2012] CreateProcH::CreateProcessInternalW reported: Strlen 103 Injecting dll: C:/Users/JEAN/SplitPLayGUI-build-desktop-Qt_4_8_1_for_Desktop_-_MSVC2010__Qt_SDK__Debug/CreateProcH.dll
[Fri Nov 30 20:22:20 2012] CreateProcH::CreateProcessInternalW reported: hThread: 5360 hProcess: 5376 dwThreadId: 8376 dwProcessId: 1388
but the process fails to create or crashes not sure what is wrong,
So I just commented out
if(!CDetour::InjectDll(lpProcessInformation->hProcess,*it))
clogf("InjectDll(lpProcessInformation->hProcess,*it) FAILED!");
and everything logged the same way but the process actually created and ran, here is CDetour::InjectDll
bool CDetour::InjectDll(HANDLE hProcess ,wchar_t * pwstrDll)
{
LPVOID RemoteString, LoadLibAddy;
if(!hProcess)
return false;
LoadLibAddy = (LPVOID)GetProcAddress(GetModuleHandle(L"kernel32.dll"), "LoadLibraryW");
if(!LoadLibAddy)
{
clogf("GetProcAddress(GetModuleHandle(L\"kernel32.dll\"), \"LoadLibraryW\") FAILED WITH %d!",GetLastError());
return false;
}
RemoteString = (LPVOID)VirtualAllocEx(hProcess, NULL, (lstrlenW(pwstrDll)*2)+2, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
if(!RemoteString)
{
clogf("VirtualAllocEx(hProcess, NULL, lstrlenW(pwstrDll)+2, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); FAILED WITH %d!",GetLastError());
return false;
}
if(WriteProcessMemory(hProcess, (LPVOID)RemoteString, pwstrDll,(lstrlenW(pwstrDll)*2)+2, NULL) == 0)
{
clogf("WriteProcessMemory(hProcess, (LPVOID)RemoteString, pwstrDll,lstrlenW(pwstrDll)+2, NULL) FAILED WITH %d!",GetLastError());
return false;
}
if(CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibAddy, (LPVOID)RemoteString, NULL, NULL) == NULL)
{
clogf("CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibAddy, (LPVOID)RemoteString, NULL, NULL) FAILED WITH %d!",GetLastError());
return false;
}
return true;
}
I hope someone else could figure it out ,thanks in advance 
|
|
|
|
|
Since nobody replied I made a much deeper research on my own, and found out that I can't really use the same DLL injection way that is used when the process is already loaded.
|
|
|
|
|
this simple program supposed to run the command ls
but the output is 1 and 2.can someone explain to me why ls not working ?
#include <stdio.h>
main()
{
int pid,stat;
if((pid=fork())==0)
{
execl("/bin/","ls",NULL);
printf("1");
exit(1);
}
else
{
wait(&stat);
printf("2");
}
}
|
|
|
|
|
The first argument to execl should contain the full path to the executable you want to run:
execl("/bin/ls","ls",NULL);
|
|
|
|
|
i understant that if i have parameters i shoud write
execl("/bin/date", "date", "-u", NULL);
how can i write the same thing with execv ?
|
|
|
|
|
Also execl returns a value that can help you tell why it isn't working.
Such as '2' which seems to pretty much always mean that it couldn't find the file it needed to execute.
|
|
|
|
|
Hello Friends
I am having a file in binary mode.Now, I want to read it So that I can get the format of that File.
Is ther any way in MFC or Win32 to reverse it ?
Thanks In Advance.
regards
yogesh
|
|
|
|
|
Unless you know the format of the file contents there is not really any way to do it. You can try some guesswork and logical tests (I have done similar in the past) but it is really down to looking at the content, and figuring out what each byte or set of bytes is supposed to represent.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
What do you mean with getting the format? If it's a binary file and you don't know how to interpret its contents, I don't think you can get a format.
Regarding the reversion, thats quite easy, although I don't see the point in doing it. You could use the functions fread(), frwite() and the like to read it into a large enough char array, loop through it from back to front and write it byte by byte into a new file (assuming is is small enough to fit into memory).
|
|
|
|
|
thanks Guys For your valuable replies.
|
|
|
|
|
yogeshs wrote: Is ther any way in MFC or Win32 to reverse it ? Reverse engineer, or reverse the contents?
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
There is a free game development tool called "Wolf RPG Editor". Details on the following site,
http://www.silversecond.com/WolfRPGEditor/[^]
The problem is that its been written in Japanese. Using Resource Hacker[^] I managed to translate one of the configuration tools that came with it. For reference here are screenshots of my efforts,
BEFORE,
http://img507.imageshack.us/img507/4545/configjapanese.jpg[^]
AFTER,
http://img811.imageshack.us/img811/3365/configenglish.jpg[^]
My next plan is to try and work with a few friends to translate the rest of the tool. Basically, it revolves around changing the text in the dialog boxes. The problem I'm facing is how to manage such a team effort.
Does anyone know a way (or utility) to extract the resources from a windows executable, split it into different files and then merge it all back together?
As useful as Resource Hacker is, its essentially a one-man tool. I'm looking for something that would let me work with a version control system for this.
On the legal side of things, I've been led to understand that the original developer has granted permission for translation efforts (admittedly, hearsay from others). The way I see things, since its a free tool and because I'm only translating it, there shouldn't be any trouble.
-chronodekar
|
|
|
|
|
There's a bunch of commercially availble tools for the job, you could check out Deja Vu, SDL Passolo or Idiom. If you google around for Flexytrans, you may find that one (it should be for free if you manage to find it).
The more elaborate tools have loads of functions for working in teams. For the simpler ones, use the Clipboard to export the strings to text files.
|
|
|
|
|
Compile same code twice, why the result(exe) is not same。both release mode and debug mode exist the same problem。if want to get same result, how to setting to the project, such as compile option。
|
|
|
|
|