|
Member 9350237 wrote: I can't proceed. Without more information we have no way of guessing what may be wrong. Look in the directory tree for the project and check that the excutable actually exists. Try starting it from Windows Explorer to see if it runs.
|
|
|
|
|
If you have multiple project in your solution, check that your project is really the "Startup Project"
I'd rather be phishing!
|
|
|
|
|
Hello, i'm trying to write a simple VSS based restore program in C++. I've read the microsoft documentation on how to perform a restore under VSS but it is not helping very much. Does anyone can help with a sample program or point me towards any useful documentation?
Thanks
|
|
|
|
|
|
(not really urgent, just a general question)
I want to "owner draw" a CStatic to have a custom "GroupBox".
The documentation says that I need to add the SS_OWNERDRAW style to the control; The resource editor does not let me change the style (there's no toggle for that).
So, I added a variable to my test dialog and tried to use ModifyStyle to add the SS_OWNERDRAW style in the dialog OnInitDialog (after the control is created).
I also tried to change the style in custom CStatic's PreSubclassWindow method; but that does not work.
Both changes did not work as expected.
I tried manually create the control in the dialog OnInitDialog; this is the work-around I am using now.
CRect rect;
GetClientRect(rect);
rect.DeflateRect(10, 10, 10, 10 );
m_CustomGroup.Create(_T(""), SS_OWNERDRAW|WS_CHILD|WS_VISIBLE, rect, this, IDC_CUSTOM_STATIC );
This works, but I remove the ability to use the resource editor to manage the custom static.
Is this the proper way to do it?
Thanks.
Max.
I'd rather be phishing!
|
|
|
|
|
I had a similar problem a few weeks ago. I solved it by manually editing the resource file containing the dialog box and adding the style that way.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I tried modifying the resource manually but the resulting control is not a groupbox and the framework does not call my overridden DrawItem and the resulting control in the dialog is completely wrong.
This is my resource definition.
IDD_TESTDIALOG_DIALOG DIALOGEX 0, 0, 320, 200
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "testDialog"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
GROUPBOX "Static",IDC_CUSTOM_STATIC,57,7,48,40, SS_OWNERDRAW
END
void CColorGroupBox::PreSubclassWindow()
{
__super::PreSubclassWindow();
}
void CColorGroupBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct )
{
CDC dc;
dc. Attach (lpDrawItemStruct->hDC);
CRect rect;
GetClientRect(rect);
rect.DeflateRect(10, 10, 10, 10);
CBrush brush( RGB( 255, 0, 0));
dc.FrameRect( rect , &brush );
dc.Detach();
}
Am I missing something ?
Thanks Richard,
Max.
I'd rather be phishing!
|
|
|
|
|
The usual method to switch to ownerdraw style is to use PreSubclassWindow:
void CMyStatic::PreSubclassWindow()
{
VERIFY(ModifyStyle(SS_TYPEMASK, SS_OWNERDRAW, 0));
CStatic::PreSubclassWindow();
}
Note that SS_TYPEMASK should be passed for the flags to be removed because the lower style bits are not ored options but enumerations. If the current style is not SS_LEFT (which is zero) but set to something else in the resource editor, the resulting style might be not owner draw.
The probable reason that this style can't be set in the resource editor is that owner drawn controls must implement the DrawItem function. This can't be checked by the resource editor.
|
|
|
|
|
Thanks,
I tried that, but it does not work, the ModifyStyle "works" (does not fail), but the DrawItem is not called.
SS_TYPEMASK is now obsolete, msdn says we should not use it.
There are other controls that I can set as Owner draw in the resource editor (for example List box) and will ASSERT when run and the (related) DrawItem is not defined.
I'd rather be phishing!
|
|
|
|
|
I have used this method and it works (I have just looked it up in a project but that still uses VS 2003).
SS_TYPEMASK is used in my example as what it is: A mask to ensure that other bits are cleared to avoid setting a wrong style.
You may check the resulting style for a proper value (call GetStyle after changing the style).
|
|
|
|
|
Initially we have designed a client server model with named pipes.
Where Server is capable of handling only one client.
We expanded the server to hold 4 client instances at a time.
After which application hangs frequently while connection is established between client and Server.
Added the code snippet below.
Please look at the snippet and suggest Is it a right method to handle multiple clients.
//Client.c
rhPipe = CreateFile("\\\\.\\Pipe\\Send", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if(rhPipe == INVALID_HANDLE_VALUE)
{
rhPipe = NULL;
return;
}
whPipe = CreateFile("\\\\.\\Pipe\\Recv", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if(whPipe == INVALID_HANDLE_VALUE)
{
whPipe = NULL;
return;
}
char message[512];
char buffer[1024];
BOOL writeStatus = FALSE;
BOOL bResult = FALSE;
DWORD cbBytes = 0;
COMMTIMEOUTS cto;
cto.ReadIntervalTimeout = 5;
cto.ReadTotalTimeoutConstant = 5*1000;
SetCommTimeouts(rhPipe, &cto);
while(1)
{
memset(message,0,sizeof(message));
strcpy(message,"Message From Client.... !!!");
writeStatus = FALSE;
cbBytes = 0;
writeStatus = WriteFile(whPipe, message, sizeof(message), &cbBytes, NULL);
if(writeStatus == FALSE || cbBytes != sizeof((message))
{
return;
}
memset(&buffer,0,sizeof(buffer));
bResult = ReadFile(rhPipe, &buffer, 1024, &cbBytes, NULL);
if(bResult == TRUE)
{
if(cbBytes == 0 )
printf("Receive from Pipe Timeout.... \n");
else
{
printf("Data Received From Server...: %s\n,buffer);
}
}
else
{
if(GetLastError() != 0)
{
CloseHandle(rhPipe);
CloseHandle(whPipe);
return;
}
}
}
//Server.c
typedef struct
{
OVERLAPPED oOverlap;
HANDLE hPipeInst;
CHAR chRequest[BUFFER_SIZE];
DWORD cbRead;
TCHAR chReply[BUFFER_SIZE];
DWORD cbToWrite;
DWORD dwState;
BOOL fPendingIO;
int processId;
} PIPEINST, *LPPIPEINST;
#define RECEIVING_PIPE 0
#define TRANSMITTING_PIPE 1
#define INSTANCES 4
PIPEINST Pipe[INSTANCES];
HANDLE hEvents[INSTANCES];
int CreateIPCPipe(int option)
{
char log_buf[512];
switch(option)
{
case RECEIVING_PIPE:
{
int i;
for (i = 0; i < INSTANCES; i++)
{
hEvents[i] = CreateEvent(NULL,TRUE,FALSE, NULL);
if (hEvents[i] == NULL)
{
return 0;
}
Pipe[i].oOverlap.hEvent = hEvents[i];
Pipe[i].hPipeInst = CreateNamedPipe("\\\\.\\Pipe\\Recv", PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, INSTANCES, BUFFER_SIZE, BUFFER_SIZE, PIPE_TIMEOUT, NULL);
if (Pipe[i].hPipeInst == INVALID_HANDLE_VALUE)
{
return 1;
}
else
{
if( Pipe[i].hPipeInst == NULL )
return 2;
}
Pipe[i].fPendingIO = ConnectToNewClient( Pipe[i].hPipeInst, &Pipe[i].oOverlap);
Pipe[i].dwState = Pipe[i].fPendingIO ? CONNECTING_STATE : READING_STATE;
}
}
break;
case TRANSMITTING_PIPE:
{
HANDLE hThread = NULL;
DWORD dwThreadId;
hThread = CreateThread(NULL,0,responsePipeConnectionHandler,NULL,0,&dwThreadId);
if (hThread == NULL)
{
memset(log_buf,0,sizeof(log_buf));
sprintf(log_buf,"Response server creation failed with %d.", GetLastError());
debug_log(log_buf,DEBUG_LOG);
return 1;
}
}
break;
default:
break;
}
return 0;
}
BOOL ConnectToNewClient(HANDLE hPipe, LPOVERLAPPED lpo)
{
char log_buf[512];
BOOL fConnected, fPendingIO = FALSE;
lpo->Offset = 0;
lpo->OffsetHigh = 0;
fConnected = ConnectNamedPipe(hPipe, lpo);
if (fConnected)
{
memset(log_buf,0,sizeof(log_buf));
sprintf(log_buf,"ConnectNamedPipe failed with %d.", GetLastError());
debug_log(log_buf,DEBUG_LOG);
return 0;
}
switch (GetLastError())
{
// The overlapped connection in progress.
case ERROR_IO_PENDING:
fPendingIO = TRUE;
break;
case ERROR_PIPE_CONNECTED:
if (SetEvent(lpo->hEvent))
break;
default:
{
memset(log_buf,0,sizeof(log_buf));
sprintf(log_buf,"ConnectNamedPipe failed with %d.", GetLastError());
debug_log(log_buf,DEBUG_LOG);
return 0;
}
}
return fPendingIO;
}
VOID DisconnectAndReconnect(DWORD i)
{
char log_buf[512];
debug_log("Disconnect and reconnect called",DEBUG_LOG);
if (! DisconnectNamedPipe(Pipe[i].hPipeInst) )
{
memset(log_buf,0,sizeof(log_buf));
sprintf(log_buf,"DisconnectNamedPipe failed with %d.", GetLastError());
debug_log(log_buf,DEBUG_LOG);
}
Pipe[i].fPendingIO = ConnectToNewClient(Pipe[i].hPipeInst, &Pipe[i].oOverlap);
Pipe[i].dwState = Pipe[i].fPendingIO ? CONNECTING_STATE : READING_STATE;
}
HANDLE GetResponseInstance()
{
//Returns Writing Instance
}
int RecvAndProcessPipeMsg()
{
char log_buf[512];
int i = 0;
BOOL wr_status = FALSE;
char message[512};
while (1)
{
BOOL isNewConnetion = FALSE, fSuccess = FALSE,dwWait = FALSE;
int cbRet = 0,dwErr = 0;
dwWait = WaitForMultipleObjects(INSTANCES, hEvents, FALSE, INFINITE);
i = dwWait - WAIT_OBJECT_0; // determines which pipe
if (i < 0 || i > (INSTANCES - 1))
{
printf("Index out of range: %d\n",i);
continue;
}
// Get the result if the operation was pending.
if (Pipe[i].fPendingIO)
{
fSuccess = GetOverlappedResult(Pipe[i].hPipeInst, &Pipe[i].oOverlap, &cbRet, FALSE);
memset(log_buf,0,sizeof(log_buf));
sprintf(log_buf,"Current state system is in : %d ",Pipe[i].dwState);
debug_log(log_buf,DEBUG_LOG);
switch (Pipe[i].dwState)
{
case CONNECTING_STATE:
if (! fSuccess)
{
memset(log_buf,0,sizeof(log_buf));
sprintf(log_buf,"Error %d.", GetLastError());
debug_log(log_buf,DEBUG_LOG);
return 0;
}
else
{
Pipe[i].dwState = READING_STATE;
int clientSessionId = 0;
GetNamedPipeClientProcessId(Pipe[i].hPipeInst,&Pipe[i].processId);
GetNamedPipeClientSessionId(Pipe[i].hPipeInst,&clientSessionId);
memset(log_buf,0,sizeof(log_buf));
sprintf(log_buf,"APP THREAD Process id: %d with sessionID : %d ",Pipe[i].processId,clientSessionId);
debug_log(log_buf,DEBUG_LOG);
memset(log_buf,0,sizeof(log_buf));
sprintf(log_buf,"Connected Client process id: %d",Pipe[i].processId);
debug_log(log_buf,DEBUG_LOG);
}
break;
case READING_STATE:
if (! fSuccess || cbRet == 0)
{
DisconnectAndReconnect(i);
continue;
}
Pipe[i].cbRead = cbRet;
Pipe[i].dwState = WRITING_STATE;
break;
case WRITING_STATE:
if (! fSuccess || cbRet != Pipe[i].cbToWrite)
{
DisconnectAndReconnect(i);
continue;
}
Pipe[i].dwState = READING_STATE;
break;
default:
{
debug_log("Invalid pipe state.",DEBUG_LOG);
return 0;
}
break;
}
}
// The pipe state determines which operation to do next.
switch (Pipe[i].dwState)
{
case READING_STATE:
debug_log("Now in read mode ",DEBUG_LOG);
fSuccess = ReadFile(Pipe[i].hPipeInst,Pipe[i].chRequest,BUFFER_SIZE,&Pipe[i].cbRead,&Pipe[i].oOverlap);
if (fSuccess && Pipe[i].cbRead != 0)
{
Pipe[i].fPendingIO = FALSE;
Pipe[i].dwState = WRITING_STATE;
continue;
}
dwErr = GetLastError();
if (! fSuccess && (dwErr == ERROR_IO_PENDING))
{
Pipe[i].fPendingIO = TRUE;
continue;
}
DisconnectAndReconnect(i);
break;
case WRITING_STATE:
debug_log("Now in WRITE STATE mode ",DEBUG_LOG);
if(isNewConnetion)
{
debug_log("AUTH NEGO ON PROGRESS ",DEBUG_LOG);
Pipe[i].fPendingIO = FALSE;
Pipe[i].dwState = READING_STATE;
isNewConnetion=FALSE;
continue;
}
else
{
Pipe[i].fPendingIO = FALSE;
Pipe[i].dwState = READING_STATE;
HANDLE responsePipe = GetPipeInfoFromTable(Pipe[i].processId);
if (responsePipe != NULL)
{
debug_log("Request has been obtained",DEBUG_LOG);
memset(&message,0,sizeof(message));
memcpy(&message,&Pipe[i].chRequest,sizeof(message));
printf("Received a new Request: %s\n",message);
HANDLE whPipe = GetResponseInstance();
wr_status = WriteFile(whPipe,"Server Received your Request", size,&cbBytes,NULL);
}
else
{
debug_log("Client response pipe not connected",DEBUG_LOG);
}
continue;
}
dwErr = GetLastError();
if (! fSuccess && (dwErr == ERROR_IO_PENDING))
{
Pipe[i].fPendingIO = TRUE;
continue;
}
DisconnectAndReconnect(i);
break;
default:
{
debug_log("Invalid pipe state.",DEBUG_LOG);
return 0;
}
break;
}
}
}
int responsePipeConnectionHandler(VOID)
{
char log_buf[512];
BOOL fConnected = FALSE;
HANDLE hPipe = INVALID_HANDLE_VALUE;
while (1)
{
memset(log_buf,0,sizeof(log_buf));
sprintf(log_buf,"Pipe Server: Main thread awaiting client connection on %s", "\\\\.\\Pipe\\ptrSend");
debug_log(log_buf,DEBUG_LOG);
hPipe = CreateNamedPipe("\\\\.\\Pipe\\ptrSend", PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES,BUFFER_SIZE, BUFFER_SIZE,0, NULL);
if (hPipe == INVALID_HANDLE_VALUE)
{
memset(log_buf,0,sizeof(log_buf));
sprintf(log_buf,"CreateNamedPipe failed, GLE=%d.", GetLastError());
debug_log(log_buf,DEBUG_LOG);
return -1;
}
fConnected = ConnectNamedPipe(hPipe, NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED);
if(fConnected)
{
int *clientProcessId = (int *)malloc(sizeof(int));
int clientSessionId = 0;
GetNamedPipeClientProcessId(hPipe,&clientProcessId);
GetNamedPipeClientSessionId(hPipe,&clientSessionId);
memset(log_buf,0,sizeof(log_buf));
sprintf(log_buf,"APP response Process id: %d with sessio nID : %d ",clientProcessId,clientSessionId);
debug_log(log_buf,DEBUG_LOG);
}
}
return 0;
}
BOOL WriteBackToPipe(int EventType, HANDLE whPipe,MSG_STRUCT *message, int size)
{
if(EventType == REGULAR_EVENTS_AND_MESSSAGES && message->msgBuffer.m_dwCategory == CAM_SERVICE_OFFSET)
{
ParseAndSendErrorEvents(message);
message->msgBuffer.m_dwCategory = CAM_SERVICE_OFFSET;
}
g_mutex_lock(write_mutex);
BOOL wr_status = FALSE;
DWORD cbBytes = 0;
if(whPipe != NULL)
{
wr_status = WriteFile(whPipe,message, size,&cbBytes,NULL);
if(wr_status == FALSE)
{
debug_log("Write to pipe failed....",DEBUG_LOG);
}
}
g_mutex_unlock(write_mutex);
return wr_status;
}
|
|
|
|
|
Please edit your question and format your code properly by using the code button above the edit box, or add <pre></pre> tags around it. you also need to indicate where in the code things are going wrong.
|
|
|
|
|
Dear all:
I am new one in win ce 6.0 driver developement.
My question is:
1.How to implement usb touch driver in win ce 6.0?
I am not sure implemented touch driver by usb client driver in win ce 6.0 or this way https://msdn.microsoft.com/en-us/library/ms895471.aspx[^]
Thank for your help, Victor
modified 21-Apr-15 4:42am.
|
|
|
|
|
|
Hello,
I wonder if there are compatibility issues with "exe" created by my project and Windows.
I use Visual Studio 2008 for MFC projects.
When I compile I create a project file that run on my PC (Windows XP)
Can the "exe" file be executed in every Windows (XP, Vista, 7,8) without problems or do I have put some particular settings during compilation in order to get a universal exe that works in every machine?
|
|
|
|
|
|
lor75 wrote:
Can the "exe" file be executed in every Windows (XP, Vista, 7,8) without problems or do I have put some particular settings during compilation in order to get a universal exe that works in every machine? Read up on Visual C++ Redistributable for Visual Studio.
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
They already gave you some good links. Anyway if your problem is to understand if the exe structure itself is compatible between last 5 Os's the answer is yes. The executable format (PECOFF) is the same as the resources format.
More different is the situation from system calls point of view. If an exe using very 'basic' functions can happily run from NT4.0 to WIN10, the things changes as you use new functions from OS or libraries (ie MFC) that were not present in former releases.
So if you want to know if your exec from VC2008 under XP will run on Win7 and Win8 it will do it on 99% of cases.
Instead if you want to build an exe that can run on all OS's from NT on carefully choose the functions you use in your code (or prefer API programming).
P.S. The graphical aspect can be changed between the OS's using an external manifest file with the compatibility fields correctly compiled allowing each OS to use last version of GUI DLL's.
|
|
|
|
|
It should work... however, the libraries used have to be present on that system (unless you explicitly used static linking, which is not the default). MS does package the "redistributables" nicely into an installer for you though. Just make sure that gets installed first or include it along with an installer for your own program and you'll be set.
MS VS2008 x86 Redistributable [^] (there is also a 64bit version, if you don't know which one you're using, it's likely x86 since that's the default build type in 2008 if I remember correctly)
|
|
|
|
|
Hi,
I am creating a child process from a console project way back when I think VS2008
I used to code a _asm { int 3 } to debug the child process the assembler interface is
no longer supported under VS2012 so I have tried DebugBreak(); __debugbreak
In the constructer of the CwinApp or in the InitInstance but nothing happens
When I right click on it to run nothing happens
The CreateProcess in the console process gets a 1 so that works
The only way I can get into the code is if I bring up another instance of VS2012
as this app is another project in the solution and debug from there
any ideas as to why the debugger isn't being invoked would be helpful
thanks
|
|
|
|
|
Hi
This is a follow up to previous message I went back to the parent process
and used the following two flags in the CreateProcess DEBUG_PROCESS and DEBUG_ONLY_THIS_PROCESS
Well back when I was using VS2008 I would get a dialog box informing the VSDebugger
was debugging the process
Now nothing maybe the app crashed before it hit CWinApp constructer where I had the
DebugBreak();
when I went to the "DEBUG" menu item -> Attach to Process I noticed my app on the selection list
When I tried to attach it I got a message Already attached to Debugger
I have no idea what debugger as I only had the original instance to VS2012 running (at least that I could see)
Any help would be appreciated
|
|
|
|
|
Hi
It is apparent there is a issue with debugbreak()
Whether it's windows 8.1 or VS 2012 I don't know
I know I did _asm
{ int 3 }
On my window 7 vs 2010 and it worked
So I am thinking how about this
CreateProces(NULL,
if DEBUG
"C:\windows\system32\vsjitdebugger.exe myprog.exe",
end
else
"myprog.exe",
end
Rest of paramters
|
|
|
|
|
Can you not run the process directly in VS and debug it in the normal way?
|
|
|
|
|
Hi
it just dies somewhere my feeling is there is something amiss in the startup code
as I put DebugBreak(); In The CWinapp constructer
The only way I can debug it if I right click on it VS it gives the option to debug
I know the startup code for a MFC app is somewhere in VS->VC->ATLMFC folder
just trying to figure which one and put a Debugbreak() there
thanks
|
|
|
|
|
hi,
still looking at my problem with debugbreak
for some reason vsjitdebugger which would normally being up a dialog box to chose a debugger
doesn't do that on windows 8.1 vs 2012 pro laptop I think that's part of the problem
Thanks
|
|
|
|
|