|
Hi All
How can i convert data from DVD to CD?Plz give me logic or link.
Thanks in Advance
|
|
|
|
|
Well, yours is a bad question.
Roughly speaking, from the programmer point of view (you know, this is a forum for programmers), there's not a big difference between a DVD and a CD (apart of their capacities).
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]
|
|
|
|
|
Since you are located in the US (according to your profile) I can't pick up your brainwaves and read your mind because the distance is too great.
Therefore, you'll have to re-phrase your question and/or eleborate on what you are trying to achieve.
|
|
|
|
|
Michael Schubert wrote: Since you are located in the US (according to your profile) I can't pick up your brainwaves and read your mind because the distance is too great
He he he... are you one of victim of google brainwave software!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
I have used VC6++ for several years. I am thinking about getting Visual Studio 2008. A friend of mine has it and I was playing around with it. I have a couple of simple quesitons.
I didn't see any option to create an exe file with static libraries. I saw where you could create installation packages but I like the ability to create a standard exe where the user doesn't have to install anything. Can this be done with VC++ 2008?
Also, will I be able to install Visual Studio 2008 without it breaking the Visual Studio 6?
The reason I am considering 2008 is because I cannot run VC6++ in debug mode when linking against the latest WinDDK release. Apparently that breaks debug mode.
Thanks in advance.
Ray
|
|
|
|
|
2buck56 wrote: I didn't see any option to create an exe file with static libraries
There is option to staticaly link the MFC and CRT with the exe. Ttake Project->Properties->Use of MFC
2buck56 wrote: but I like the ability to create a standard exe where the user doesn't have to install anything
If you put the necessary dll's in the same folder of your binary, you dont have to install anything special. isnt it?
2buck56 wrote: Also, will I be able to install Visual Studio 2008 without it breaking the Visual Studio 6?
Ya. It wont break anything of visual studio 6. I have vs6, vs2005 and vs2008 installed in my machine
|
|
|
|
|
|
Naveen and Saurabh,
Thanks for the quick answer. I believe I will go ahead and get VS2008 and start learning it. Since I will be able to keep VC6++ installed I can maintain existing projects until I get them switched over.
|
|
|
|
|
You are welcome.
-Saurabh
|
|
|
|
|
I have a program in c builder and I have several buttons that access sounds. How do you play several sounds at once? For example if you press a button while running a sound it will interrupt the present one. I use the PlaySound function. Thanks!
|
|
|
|
|
What are the files to keep with the static c/c++ lib after it was built in debug mode to enable its source code step into debugging from some executable linked to it?
E.g. there are .obj, .ncb, .idb, .pdb etc... files after the build. Which ones are related to step into the lib code?
Чесноков
|
|
|
|
|
.pdb is required for this - it's the debug symbols. I believe that's all you need.
L u n a t i c F r i n g e
|
|
|
|
|
Yes you only need PDB files.
-Saurabh
|
|
|
|
|
Hi,
I want to make a game of TicTacToe. WhenI resize the window I want to appear more buttons on the interface. From a matrix of 3x3 to 4x4 etc up to 9x9, depending on how much I resize the window. How do I do this?
I will make a free web site design to whoever provides me with a working answer (and something extra for the full program of playing tictactoe).
Thank you!
modified on Wednesday, January 6, 2010 3:28 PM
|
|
|
|
|
can somebody help me in understanding basic c++ connectivity with sql 2005...
i am good in c# trying to learn C++ database part..
i want to know which header file i need to use..?
and how different the programming is from C#
vikas da
|
|
|
|
|
tasumisra wrote: can somebody help me in understanding basic c++ connectivity with sql 2005...
Yes, if you come up with a specific query.
tasumisra wrote: i am good in c# trying to learn C++ database part..
If you're using MFC, you may lookup the CDatabase class. You have other options like ADO, ODBC (without MFC as well), etc., There are a whole lot of articles on CP at all levels of complexity. You may want to read some of those from the beginner's section.
tasumisra wrote: and how different the programming is from C#
There's no comparison between C# and C++.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Rajesh R Subramanian wrote: There's no comparison between C# and C++
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]
|
|
|
|
|
What is mean by canonical assignment operator? If any one knows, pls help.
|
|
|
|
|
|
Hi.
I have the follow pieces of code. A Server and Client code I wrote. I have a few problems. If I disable the sending data from the client and the receving data from the server. Everything works ok for somewhere between 900-4000 times. I then get WriteFileEx returned GetLastError 1450. If I disconnect the client and rerun the application, the Server works again for another 900-4000 times before another 1450 error.
As the code stands, at some point, between 1 and 5 times, both programs just freeze. No errors, nothing.
I can't see the money leak and I am only sending 34bytes to the client and retrieving 4bytes. I'm not doing anything more than 64bytes of memory. I really don't know what the problem is.
Can anyone see the problems I have?
Thanks,
#pragma warning(disable:4995)
#pragma comment(lib, "shell32.lib")
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <strsafe.h>
#include <time.h>
#include "psapi.h"
#define FNAME_LEN 1000
#define PNAME_LEN 1000
#define SEND_LEN 1024
#define RECV_LEN 64
typedef struct _PIPEINST
{
OVERLAPPED Overlapped;
HANDLE hPipe;
TCHAR tzSend[SEND_LEN];
DWORD dwSendLength;
TCHAR tzRecv[RECV_LEN];
DWORD dwRecvLength;
} PIPEINST, *PPIPEINST;
typedef struct _THREAD_CONTEXT
{
HANDLE hPort;
HANDLE hCompletion;
DWORD uTemporary;
} THREAD_CONTEXT, *PTHREAD_CONTEXT;
HANDLE NewPipe(LPWSTR PipeName, LPOVERLAPPED lpOverlapped)
{
HANDLE hPipe;
hPipe=CreateNamedPipe(PipeName, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, PNAME_LEN*sizeof(TCHAR), PNAME_LEN*sizeof(TCHAR), 1, NULL);
if(hPipe == INVALID_HANDLE_VALUE)
{
printf("CreateNamedPipe failed.\n");
return NULL;
}
if((ConnectNamedPipe(hPipe, lpOverlapped)))
{
printf("ConnectNamedPipe failed.\n");
return NULL;
}
return hPipe;
}
VOID WINAPI CompletedWrite(DWORD dwErr, DWORD dwWritten, LPOVERLAPPED lpOverLap)
{
printf("Written %d.\n", dwWritten);
}
BOOLEAN SendToGUI(HANDLE hPipe, PPIPEINST pPipeInst, DWORD numb, PWCHAR str)
{
PWCHAR buffer;
buffer = (PWCHAR) malloc (SEND_LEN);
swprintf(buffer, L"%d\t%ws\0\0", numb, str);
printf("Sending.. %ws\n", buffer);
StringCchCopy(pPipeInst->tzSend, wcslen(buffer)+2, buffer);
pPipeInst->dwSendLength = (wcslen(pPipeInst->tzSend) * 2);
if(WriteFileEx(hPipe, pPipeInst->tzSend, pPipeInst->dwSendLength + 2, (LPOVERLAPPED) pPipeInst, (LPOVERLAPPED_COMPLETION_ROUTINE) CompletedWrite))
{
free(buffer);
return TRUE;
}
else
{
printf("WriteFileEx failed '%d'.\n", GetLastError());
free(buffer);
return FALSE;
}
}
VOID WINAPI CompletedRead(DWORD dwErr, DWORD dwRead, LPOVERLAPPED lpOverLap)
{
printf("Read %d bytes.\n", dwRead);
}
DWORD ReceiveFromGUI(HANDLE hPipe, PPIPEINST pPipeInst)
{
DWORD BytesRead = 0;
pPipeInst->dwRecvLength = 0;
if(ReadFileEx(hPipe, pPipeInst->tzRecv, RECV_LEN, (LPOVERLAPPED) pPipeInst, (LPOVERLAPPED_COMPLETION_ROUTINE) CompletedRead))
{
return TRUE;
}
else
{
printf("ReadFileEx failed.\n");
return FALSE;
}
}
DWORD Thread(PTHREAD_CONTEXT pThreadContext)
{
OVERLAPPED hEventOverlapped;
PWCHAR PipeName;
HANDLE hPipe;
HANDLE hEvent;
PPIPEINST pPipeInst;
BOOLEAN IsConnected;
if((hEvent=CreateEvent(NULL, TRUE, TRUE, NULL)) == NULL)
{
printf("CreateEvent failed.\n");
goto end_thread;
}
else
{
hEventOverlapped.hEvent = hEvent;
}
if((PipeName=(PWCHAR) malloc(PNAME_LEN+2)) == NULL)
{
printf("malloc(PipeName) failed.\n");
goto end_thread;
}
swprintf(PipeName, L"\\\\.\\pipe\\PipeName%d\0", pThreadContext->uTemporary);
printf("PipeName %ws.\n", PipeName);
pThreadContext->uTemporary = 1;
IsConnected = FALSE;
if((pPipeInst = (PPIPEINST) GlobalAlloc(GPTR, sizeof(PIPEINST)+2)) !=NULL)
if((hPipe = NewPipe (PipeName, &hEventOverlapped)) !=NULL)
while(TRUE)
{
if(!IsConnected)
{
WaitForSingleObjectEx(hEvent, INFINITE, TRUE);
printf("Client has connected.\n");
IsConnected = TRUE;
}
ConnectNamedPipe(hPipe, &hEventOverlapped);
if(GetLastError() != ERROR_PIPE_CONNECTED || GetLastError() == ERROR_PIPE_LISTENING)
{
printf("Client has disconnected.\n");
IsConnected = FALSE;
DisconnectNamedPipe(hPipe);
CloseHandle(hPipe);
if((hPipe = NewPipe (PipeName, &hEventOverlapped)) == NULL)
{
printf("Unable to recreate new pipe.\n");
break;
}
}
else
{
if((SendToGUI(hPipe, pPipeInst, 1, L"string")) == FALSE)
{
printf("SendToGUI failed '%d'\n", GetLastError());
}
else
{
WaitForSingleObjectEx(hEvent, INFINITE, TRUE);
ReceiveFromGUI(hPipe, pPipeInst);
WaitForSingleObjectEx(hEvent, INFINITE, TRUE);
printf("Retrieved %c\n", pPipeInst->tzRecv[0]);
}
}
}
end_thread:
printf("%ws pipe exiting..\n", PipeName);
if(PipeName == NULL); else free(PipeName);
if(hPipe == NULL); else CloseHandle(hPipe);
if(pPipeInst == NULL); else free(pPipeInst);
return 1;
}
void __cdecl main()
{
HANDLE hThread[1];
THREAD_CONTEXT ThreadContext;
DWORD dwThreadId;
DWORD dwi;
for (dwi=0; dwi<1; dwi++)
{
ThreadContext.uTemporary = dwi;
hThread[dwi] = CreateThread(NULL, 0, Thread, &ThreadContext, 0, &dwThreadId);
if(hThread[dwi] == NULL)
{
printf("CreateThread failed.\n");
return;
}
while(ThreadContext.uTemporary == dwi);
}
WaitForMultipleObjectsEx(dwi, hThread, TRUE, INFINITE, FALSE);
printf("Exit success.\n");
return;
}
Client Code
#pragma warning(disable:4995)
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <winioctl.h>
#include <string.h>
#include <crtdbg.h>
#include <assert.h>
#include <fltuser.h>
#include <wchar.h>
#include <strsafe.h>
#include <conio.h>
#define RECV_LEN 1000
#define SEND_LEN 1000
#define PNAME_LEN 1000
int OpenPipe(DWORD PipeNumber, PCHAR PipeName);
int ReadPipe(DWORD PipeNumber, PCHAR PipeRead, DWORD ReadLength);
int WritePipe(DWORD PipeNumber, PCHAR PipeWrite, DWORD WriteLength);
int ClosePipe(DWORD PipeNumber);
typedef struct _PIPEINST
{
OVERLAPPED Overlapped;
HANDLE hPipe;
TCHAR tzSend[SEND_LEN];
DWORD dwSendLength;
TCHAR tzRecv[RECV_LEN];
DWORD dwRecvLength;
DWORD dwState;
BOOL fPendingIO;
} PIPEINST, *PPIPEINST;
PPIPEINST pPipeInst[1];
HANDLE hEvents[1];
int WriteToLog(char* uString)
{
FILE* pFile;
if((pFile = fopen("logfile.log", "a+")) == NULL) return -1;
printf("%s\n", uString);
fclose(pFile);
return 0;
}
int __stdcall OpenPipe(DWORD PipeNumber, PCHAR PipeName)
{
DWORD dwMode;
BOOL fSuccess = FALSE;
WCHAR wBuffer[PNAME_LEN];
UCHAR ErrorMessage[1024];
pPipeInst[PipeNumber] = (PPIPEINST) malloc (sizeof(PIPEINST));
MultiByteToWideChar(CP_ACP, 0, PipeName, -1, wBuffer, strlen(PipeName));
wBuffer[strlen(PipeName)] = '\0';
hEvents[PipeNumber] = CreateEvent(NULL, TRUE, TRUE, NULL);
if(hEvents[PipeNumber] == NULL)
{
printf("CreateEvent failed.\n");
return 1;
}
pPipeInst[PipeNumber]->Overlapped.hEvent = hEvents[PipeNumber];
while (1)
{
pPipeInst[PipeNumber]->hPipe = CreateFile(wBuffer, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
if (pPipeInst[PipeNumber]->hPipe != INVALID_HANDLE_VALUE) break;
if (GetLastError() != ERROR_PIPE_BUSY) return 1;
if (!WaitNamedPipe(wBuffer, 20000)) return 1;
}
dwMode = PIPE_TYPE_BYTE;
fSuccess = SetNamedPipeHandleState(pPipeInst[PipeNumber]->hPipe, &dwMode, NULL, NULL);
if (!fSuccess) return 1;
return 0;
}
int __stdcall ReadPipe(DWORD PipeNumber, PCHAR pPipeRead, DWORD ReadLength)
{
PWCHAR PipeRead;
BOOL fSuccess = FALSE;
PipeRead = (PWCHAR) malloc (RECV_LEN);
if(PipeRead == NULL)
{
printf("malloc(PipeRead) failed.\n");
return 0;
}
ReadFile(pPipeInst[PipeNumber]->hPipe, PipeRead, RECV_LEN, NULL, &pPipeInst[PipeNumber]->Overlapped);
fSuccess = GetOverlappedResult(pPipeInst[PipeNumber]->hPipe, &pPipeInst[PipeNumber]->Overlapped, &ReadLength, FALSE);
if(fSuccess)
{
sprintf(pPipeRead, "%ws\0", PipeRead);
free(PipeRead);
return ReadLength;
}
free(PipeRead);
return 0;
}
int __stdcall WritePipe(DWORD PipeNumber, PCHAR PipeWrite, DWORD WriteLength)
{
BOOL fSuccess = FALSE;
PWCHAR wBuffer;
DWORD cbWritten;
wBuffer = (PWCHAR) malloc (SEND_LEN);
if(wBuffer == NULL)
{
printf("malloc(wBuffer) failed.\n");
return 1;
}
MultiByteToWideChar(CP_ACP, 0, PipeWrite, -1, wBuffer, strlen(PipeWrite));
wBuffer[strlen(PipeWrite)] = '\0';
fSuccess = WriteFile(pPipeInst[PipeNumber]->hPipe, wBuffer, wcslen(wBuffer) * 2, &cbWritten, NULL);
if (!fSuccess)
{
free(wBuffer);
return 1;
}
else
{
free(wBuffer);
return 0;
}
}
int __stdcall ClosePipe(DWORD PipeNumber)
{
CloseHandle(pPipeInst[PipeNumber]->hPipe);
return 0;
}
void __cdecl main()
{
PCHAR Pipe;
DWORD n = 0;
DWORD ReadLength = 0;
Pipe = (PCHAR) malloc (1024);
if(OpenPipe(0, "\\\\.\\Pipe\\PipeName0") != 0) return;
printf ("Connected.\n");
while (TRUE)
{
if((ReadLength = ReadPipe(n, Pipe, 0)) > 0)
{
printf("Read (%i bytes):\n %s\n", ReadLength, Pipe);
printf("Sending..\n");
printf("Responce: %i (1 is failure.)\n", WritePipe(n, "a", 1));
}
}
return;
}
modified on Wednesday, January 6, 2010 1:57 PM
|
|
|
|
|
Well, your first problem is that you did not format your code properly i.e. within <pre></pre> tags and correctly indented. As such no-one is likely to spend much time trying to read it. Secondly, you need to either run it in the debugger or add debugging code to try and narrow down to at least the general area where it is going wrong.
|
|
|
|
|
The problem exists somewhere in the send and receive on either or both the client and the server but where and what it is I cannot figure it out. Which is why I am here.
|
|
|
|
|
noalias___ wrote: I have a few problems
You're right.
I don't read tons of unformatted code. PRE tags would take care of most formatting.
noalias___ wrote: the money leak
If R&D is exhausting your funds, the only solution is to put your product on the market ASAP, and possibly fix the remaining problems in a future service pack.
BTW: Error 1450 = Insufficient system resources exist to complete the requested service. Which probably means you forgot to free, deallocate, close, ... some memory or other resource.
|
|
|
|
|
Hi.
I have reposted it with pre tags.
I cannot see where I forgot to close anything. CLosing hPipe doesn't count as it would need to leave the while loop for that.
I am really struggling with fixing this problem. It seems so simple.
|
|
|
|
|

#pragma warning(disable:4995)
#pragma comment(lib, "shell32.lib")
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <strsafe.h>
#include <time.h>
#include "psapi.h"
#define FNAME_LEN 1000
#define PNAME_LEN 1000
#define SEND_LEN 1024
#define RECV_LEN 64
typedef struct _PIPEINST
{
OVERLAPPED Overlapped;
HANDLE hPipe;
TCHAR tzSend[SEND_LEN];
DWORD dwSendLength;
TCHAR tzRecv[RECV_LEN];
DWORD dwRecvLength;
} PIPEINST, *PPIPEINST;
typedef struct _THREAD_CONTEXT
{
HANDLE hPort;
HANDLE hCompletion;
DWORD uTemporary;
} THREAD_CONTEXT, *PTHREAD_CONTEXT;
HANDLE NewPipe(LPWSTR PipeName, LPOVERLAPPED lpOverlapped)
{
HANDLE hPipe;
hPipe=CreateNamedPipe(PipeName, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, PNAME_LEN*sizeof(TCHAR), PNAME_LEN*sizeof(TCHAR), 1, NULL);
if(hPipe == INVALID_HANDLE_VALUE)
{
printf("CreateNamedPipe failed.\n");
return NULL;
}
if((ConnectNamedPipe(hPipe, lpOverlapped)))
{
printf("ConnectNamedPipe failed.\n");
return NULL;
}
return hPipe;
}
VOID WINAPI CompletedWrite(DWORD dwErr, DWORD dwWritten, LPOVERLAPPED lpOverLap)
{
printf("Written %d.\n", dwWritten);
}
BOOLEAN sendd(HANDLE hPipe, PPIPEINST pPipeInst, DWORD numb, PWCHAR str)
{
PWCHAR buffer;
buffer = (PWCHAR) malloc (SEND_LEN);
swprintf(buffer, L"%d\t%ws\0\0", numb, str);
printf("Sending.. %ws\n", buffer);
StringCchCopy(pPipeInst->tzSend, wcslen(buffer)+2, buffer);
pPipeInst->dwSendLength = (wcslen(pPipeInst->tzSend) * 2);
if(WriteFileEx(hPipe, pPipeInst->tzSend, pPipeInst->dwSendLength + 2, (LPOVERLAPPED) pPipeInst, (LPOVERLAPPED_COMPLETION_ROUTINE) CompletedWrite))
{
free(buffer);
return TRUE;
}
else
{
printf("WriteFileEx failed '%d'.\n", GetLastError());
free(buffer);
return FALSE;
}
}
VOID WINAPI CompletedRead(DWORD dwErr, DWORD dwRead, LPOVERLAPPED lpOverLap)
{
printf("Read %d bytes.\n", dwRead);
}
DWORD recvv(HANDLE hPipe, PPIPEINST pPipeInst)
{
DWORD BytesRead = 0;
pPipeInst->dwRecvLength = 0;
if(ReadFileEx(hPipe, pPipeInst->tzRecv, RECV_LEN, (LPOVERLAPPED) pPipeInst, (LPOVERLAPPED_COMPLETION_ROUTINE) CompletedRead))
{
return TRUE;
}
else
{
printf("ReadFileEx failed.\n");
return FALSE;
}
}
DWORD Thread(PTHREAD_CONTEXT pThreadContext)
{
OVERLAPPED hEventOverlapped;
PWCHAR PipeName;
HANDLE hPipe;
HANDLE hEvent;
PPIPEINST pPipeInst;
BOOLEAN IsConnected;
if((hEvent=CreateEvent(NULL, TRUE, TRUE, NULL)) == NULL)
{
printf("CreateEvent failed.\n");
goto end_thread;
}
else
{
hEventOverlapped.hEvent = hEvent;
}
if((PipeName=(PWCHAR) malloc(PNAME_LEN+2)) == NULL)
{
printf("malloc(PipeName) failed.\n");
goto end_thread;
}
swprintf(PipeName, L"\\\\.\\pipe\\PipeName%d\0", pThreadContext->uTemporary);
printf("PipeName %ws.\n", PipeName);
pThreadContext->uTemporary = 1;
IsConnected = FALSE;
if((pPipeInst = (PPIPEINST) GlobalAlloc(GPTR, sizeof(PIPEINST)+2)) !=NULL)
if((hPipe = NewPipe (PipeName, &hEventOverlapped)) !=NULL)
while(TRUE)
{
if(!IsConnected)
{
WaitForSingleObjectEx(hEvent, INFINITE, TRUE);
printf("Client has connected.\n");
IsConnected = TRUE;
}
ConnectNamedPipe(hPipe, &hEventOverlapped);
if(GetLastError() != ERROR_PIPE_CONNECTED || GetLastError() == ERROR_PIPE_LISTENING)
{
printf("Client has disconnected.\n");
IsConnected = FALSE;
DisconnectNamedPipe(hPipe);
CloseHandle(hPipe);
if((hPipe = NewPipe (PipeName, &hEventOverlapped)) == NULL)
{
printf("Unable to recreate new pipe.\n");
break;
}
}
else
{
if((sendd(hPipe, pPipeInst, 1, L"string")) == FALSE)
{
printf("SendToGUI failed '%d'\n", GetLastError());
}
else
{
WaitForSingleObjectEx(hEvent, INFINITE, TRUE);
recvv(hPipe, pPipeInst);
WaitForSingleObjectEx(hEvent, INFINITE, TRUE);
printf("Retrieved %c\n", pPipeInst->tzRecv[0]);
}
}
}
end_thread:
printf("%ws pipe exiting..\n", PipeName);
if(PipeName == NULL); else free(PipeName);
if(hPipe == NULL); else CloseHandle(hPipe);
if(pPipeInst == NULL); else free(pPipeInst);
return 1;
}
void __cdecl main()
{
HANDLE hThread[1];
THREAD_CONTEXT ThreadContext;
DWORD dwThreadId;
DWORD dwi;
for (dwi=0; dwi<1; dwi++)
{
ThreadContext.uTemporary = dwi;
hThread[dwi] = CreateThread(NULL, 0, Thread, &ThreadContext, 0, &dwThreadId);
if(hThread[dwi] == NULL)
{
printf("CreateThread failed.\n");
return;
}
while(ThreadContext.uTemporary == dwi);
}
WaitForMultipleObjectsEx(dwi, hThread, TRUE, INFINITE, FALSE);
printf("Exit success.\n");
return;
}
The Client code.
#pragma warning(disable:4995)
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <winioctl.h>
#include <string.h>
#include <crtdbg.h>
#include <assert.h>
#include <fltuser.h>
#include <wchar.h>
#include <strsafe.h>
#include <conio.h>
#define RECV_LEN 1000
#define SEND_LEN 1000
#define PNAME_LEN 1000
int OpenPipe(DWORD PipeNumber, PCHAR PipeName);
int ReadPipe(DWORD PipeNumber, PCHAR PipeRead, DWORD ReadLength);
int WritePipe(DWORD PipeNumber, PCHAR PipeWrite, DWORD WriteLength);
int ClosePipe(DWORD PipeNumber);
typedef struct _PIPEINST
{
OVERLAPPED Overlapped;
HANDLE hPipe;
TCHAR tzSend[SEND_LEN];
DWORD dwSendLength;
TCHAR tzRecv[RECV_LEN];
DWORD dwRecvLength;
DWORD dwState;
BOOL fPendingIO;
} PIPEINST, *PPIPEINST;
PPIPEINST pPipeInst[1];
HANDLE hEvents[1];
int WriteToLog(char* uString)
{
FILE* pFile;
if((pFile = fopen("logfile.log", "a+")) == NULL) return -1;
printf("%s\n", uString);
fclose(pFile);
return 0;
}
int __stdcall OpenPipe(DWORD PipeNumber, PCHAR PipeName)
{
DWORD dwMode;
BOOL fSuccess = FALSE;
WCHAR wBuffer[PNAME_LEN];
UCHAR ErrorMessage[1024];
pPipeInst[PipeNumber] = (PPIPEINST) malloc (sizeof(PIPEINST));
MultiByteToWideChar(CP_ACP, 0, PipeName, -1, wBuffer, strlen(PipeName));
wBuffer[strlen(PipeName)] = '\0';
hEvents[PipeNumber] = CreateEvent(NULL, TRUE, TRUE, NULL);
if(hEvents[PipeNumber] == NULL)
{
printf("CreateEvent failed.\n");
return 1;
}
pPipeInst[PipeNumber]->Overlapped.hEvent = hEvents[PipeNumber];
while (1)
{
pPipeInst[PipeNumber]->hPipe = CreateFile(wBuffer, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
if (pPipeInst[PipeNumber]->hPipe != INVALID_HANDLE_VALUE) break;
if (GetLastError() != ERROR_PIPE_BUSY) return 1;
if (!WaitNamedPipe(wBuffer, 20000)) return 1;
}
dwMode = PIPE_TYPE_BYTE;
fSuccess = SetNamedPipeHandleState(pPipeInst[PipeNumber]->hPipe, &dwMode, NULL, NULL);
if (!fSuccess) return 1;
return 0;
}
int __stdcall ReadPipe(DWORD PipeNumber, PCHAR pPipeRead, DWORD ReadLength)
{
PWCHAR PipeRead;
BOOL fSuccess = FALSE;
PipeRead = (PWCHAR) malloc (RECV_LEN);
if(PipeRead == NULL)
{
printf("malloc(PipeRead) failed.\n");
return 0;
}
ReadFile(pPipeInst[PipeNumber]->hPipe, PipeRead, RECV_LEN, NULL, &pPipeInst[PipeNumber]->Overlapped);
fSuccess = GetOverlappedResult(pPipeInst[PipeNumber]->hPipe, &pPipeInst[PipeNumber]->Overlapped, &ReadLength, FALSE);
if(fSuccess)
{
sprintf(pPipeRead, "%ws\0", PipeRead);
free(PipeRead);
return ReadLength;
}
free(PipeRead);
return 0;
}
int __stdcall WritePipe(DWORD PipeNumber, PCHAR PipeWrite, DWORD WriteLength)
{
BOOL fSuccess = FALSE;
PWCHAR wBuffer;
DWORD cbWritten;
wBuffer = (PWCHAR) malloc (SEND_LEN);
if(wBuffer == NULL)
{
printf("malloc(wBuffer) failed.\n");
return 1;
}
MultiByteToWideChar(CP_ACP, 0, PipeWrite, -1, wBuffer, strlen(PipeWrite));
wBuffer[strlen(PipeWrite)] = '\0';
fSuccess = WriteFile(pPipeInst[PipeNumber]->hPipe, wBuffer, wcslen(wBuffer) * 2, &cbWritten, NULL);
if (!fSuccess)
{
free(wBuffer);
return 1;
}
else
{
free(wBuffer);
return 0;
}
}
int __stdcall ClosePipe(DWORD PipeNumber)
{
CloseHandle(pPipeInst[PipeNumber]->hPipe);
return 0;
}
void __cdecl main()
{
PCHAR Pipe;
DWORD n = 0;
DWORD ReadLength = 0;
Pipe = (PCHAR) malloc (1024);
if(OpenPipe(0, "\\\\.\\Pipe\\PipeName0") != 0) return;
printf ("Connected.\n");
while (TRUE)
{
if((ReadLength = ReadPipe(n, Pipe, 0)) > 0)
{
printf("Read (%i bytes):\n %s\n", ReadLength, Pipe);
printf("Sending..\n");
printf("Responce: %i (1 is failure.)\n", WritePipe(n, "a", 1));
}
}
return;
}
|
|
|
|
|