|
6784746 wrote: i try ,but i can't find the API what is important.
I don't understand what this has to do with your problem; what API are you referring to?
|
|
|
|
|
Thank you all
and the i hooking the "GetWindowTextW" functions
Solve this problem hahaha!.......
|
|
|
|
|
Here is an application base on a CTabView with 3 CFormView derived class.
I tracked down the size of one of the CFormView derived view (by calling GetWindowRect) and got the following:
CDataView::OnSize cx 938 cy 431 Width 938 Height 431
CDataView::OnSize cx 0 cy 0 Width 0 Height 0
CDataView::OnShowWindow
CDataView::OnShowWindow
CDataView::OnSize cx 972 cy 333 Width 989 Height 333
CDataView::OnSize cx 989 cy 333 Width 989 Height 333
CDataView::OnInitialUpdate Width 989 Height 333
CDataView::OnSize cx 939 cy 333 Width 956 Height 333
CDataView::OnSize cx 955 cy 371 Width 972 Height 371
CDataView::OnSize cx 0 cy 0 Width 0 Height 0
CDataView::OnSize cx 1174 cy 521 Width 1174 Height 521
CDataView::OnSize cx 1157 cy 521 Width 1174 Height 521
Before doing anything with the window, OnSize is called 9 times and the values of cx, cy, width and height changed several times ... How can I get the final and actual values ?
|
|
|
|
|
You can only get the current value, since the window size may change at any time, as the user drags the sizing handle, presses minimize, maximize etc.
|
|
|
|
|
I guess I was not precise enough in my question ... The tracking of OnSize class (shown in the initial message) was the tracking at startup, with no user resizing... I need the size at startup after the initialization of the application window (that is, before user change the size of the application window...) So that I can use these informations for dynamic child controls resizing. When I use existing controls-resizing class, the positioning/resizing of the child controls is not accurate for the application I'm working on now (vs2010 - MDI with a CTabView and three CFormView-derived views)
|
|
|
|
|
I think you are missing the point. Windows are dynamic and can (and do) change throughout their existence. Your application needs to respond to these changes and repaint the contents, including any child windows, every time. There is no way to tell when the final resizing occurs after initialization; however, you can ignore messages when the width or height values are zero.
|
|
|
|
|
You should get the values in the final call.
That will be the current value.
So keep updating the storage variables with the values in OnSize every time it is called.
|
|
|
|
|
Same reply as I have done to Richard ...
I guess I was not precise enough in my question ... The tracking of OnSize class (shown in the initial message) was the tracking at startup, with no user resizing... I need the size at startup after the initialization of the application window (that is, before user change the size of the application window...) So that I can use these informations for dynamic child controls resizing. When I use existing controls-resizing class, the positioning/resizing of the child controls is not accurate for the application I'm working on now (vs2010 - MDI with a CTabView and three CFormView-derived views)
|
|
|
|
|
Hey,
I'm working on an larger project for a while and i've almost tested my application in debug mode, where it works really fine. But later on i've tested it with some brute force methods in release mode, and i've noticed that it almost crashes after some 100 test runs due a heap corruption error. As you may know heap corruption errors are really hard to find, but i've figured out that this error occurs even if I comment out about 99% of my code.
But by checking the remaining lines I find absolutely nothing ... for some moments i thought it could be caused by the reference counter of _variant_t and bstr_t but maybe thats not the error: So at first i will provide the lines to you which already cause the heap corruption:
A simple call in my main:
DDDElements::DDDDocument* pDocument = new DDDElements::DDDDocument();
Which calls this. (CLRObject(...) just sets some local variables.)
DDDDocument::DDDDocument(void) : CLRObject(NULL, NULL, NULL)
{
clr = new CLR();
clra = new CLRAssembly(clr, L"DDD");
vtCLRObject = clra->CreateInstance(THISDOTNETTYPE());
}
The CLR instanciation looks like this where all used methods are imported:
CLR::CLR(void)
{
this->pszVersion = L"v4.0.30319";
this->init();
}
void CLR::init() {
HRESULT hr;
BOOL bLoadable = false;
IUnknownPtr spAppDomainThunk = NULL;
hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID *)&lpMetaHost);
if(FAILED(hr)) throw "CLR instance could not be created!";
hr = lpMetaHost->GetRuntime(pszVersion, IID_ICLRRuntimeInfo, (LPVOID *)&lpRuntimeInfo);
if(FAILED(hr)) throw "Failed getting the reference to CLR interface!";
hr = lpRuntimeInfo->IsLoadable(&bLoadable);
if(FAILED(hr)) throw "Failed loading the CLR!";
if(!bLoadable) throw "CLR is not loadable!";
hr = lpRuntimeInfo->GetInterface(CLSID_CorRuntimeHost, IID_PPV_ARGS(&lpRuntimeHost));
if(FAILED(hr)) throw "Failed loading the CLR!";
hr = lpRuntimeHost->Start();
if(FAILED(hr)) throw "Failed starting the CLR!";
hr = lpRuntimeHost->GetDefaultDomain(&spAppDomainThunk);
if (FAILED(hr)) throw "Failed to get CLR default appdomain!";
hr = spAppDomainThunk->QueryInterface(IID_PPV_ARGS(&spAppDomain));
if (FAILED(hr)) throw "Failed to get CLR default appdomain!";
}
The Assembly is loaded by this few lines:
CLRAssembly::CLRAssembly(CLR* clr, PCWSTR pszAssemblyName)
{
HRESULT hr;
bstr_t bstrAssemblyName(pszAssemblyName);
this->clr = clr;
hr = clr->GetAppDomain()->Load_2(bstrAssemblyName, &spAssembly);
if(FAILED(hr)) throw "Loading of assembly failed.";
}
Then we first run THISDOTNETTYPE to pass its returnvalue to the create instance method:
_TypePtr DDDDocument::THISDOTNETTYPE()
{
return clra->BuildType(L"DDD.DDDDocument");
}
_TypePtr CLRAssembly::BuildType(PCWSTR pszClassName)
{
HRESULT hr = NULL;
bstr_t bstrClassName(pszClassName);
_TypePtr spType = NULL;
hr = spAssembly->GetType_2(bstrClassName, &spType);
if(FAILED(hr)) throw "Failed to get typereferece.";
return spType;
}
Until now just some small easy lines. Finally we run create Instance which looks like this:
_variant_t CLRAssembly::CreateInstance(_TypePtr spType)
{
SAFEARRAY* psaMethodArgs = NULL;
psaMethodArgs = SafeArrayCreateVector(VT_VARIANT, 0, 0);
return this->CreateInstance(spType, psaMethodArgs);
}
_variant_t CLRAssembly::CreateInstance(_TypePtr spType, SAFEARRAY* psaMethodArgs)
{
HRESULT hr;
_variant_t vtResult= NULL;
_variant_t vtEmpty;
if(psaMethodArgs == NULL) psaMethodArgs = SafeArrayCreateVector(VT_VARIANT, 0, 0);
hr = spType->InvokeMember_3(NULL, static_cast<BindingFlags>(
BindingFlags_CreateInstance | BindingFlags_Instance | BindingFlags_Public),
NULL, vtEmpty, psaMethodArgs, &vtResult);
if(FAILED(hr)) throw "Failed to create Instance.";
return vtResult;
}
And done.
This I run some hundred times and in 1 of 200 runs it ends up in a heap corruption error. I've absolutely no idea why. I've guessed a lot of things and googled for them, but none of them helped.
As already told i've especially looked at the reference counter of the COM types like SAFEARRAY, _variant_t and bstr_t. I thought returning them causes the error. But it seems by returning them by value should be the best answer to avoid heap corruptions there. They first make a copy of themselves, after that the free themselves. So this should work. Then i thought passing them by value could cause the error. But there the reference counter adds a reference - so it works. In the and as already told now the third time - i've absolutely no idea what causes the heap corruption. Maybe one of you will find it by first look at it
*Edit + Edit 2*
At the moment there are 2 questions I am asking myself:
1. what happens with a reference when it is copied by value, and the old variant containing this refernece is freed? As I know the garbage collector of the CLR should be inactive. But is it deleted or not? The problem is that there is no possibility to trace that.
2. Could this error may be caused by using this as a static library compiled in debug mode? Answer due testing: No.
Regards BS
modified on Saturday, August 13, 2011 10:13 AM
|
|
|
|
|
Firstly sorry for such a lengthy code.
I found this sample in codeproject. But when i try to run this. cmd.exe is not invoking.
CustomMessageSender is working ok. But LaunchAppIntoDifferentSession()fails in launching the cmd.exe. Have i missed something. I tried a lot but failed.
FileName : ServiceTwo
#pragma comment (lib,"WtsApi32.lib")
#pragma comment (lib,"UserEnv.lib")
#include <iostream>
#include <Windows.h>
#include <WinSvc.h>
#include <WtsApi32.h>
#include <UserEnv.h>
#include <TlHelp32.h>
#define SERVICE_CONTROL_CUSTOM_MESSAGE 0x095
BOOL LaunchAppIntoDifferentSession(LPWSTR appName, LPPROCESS_INFORMATION pi);
SERVICE_STATUS m_ServiceStatus;
SERVICE_STATUS_HANDLE m_ServiceStatusHandle;
BOOL bRunning =TRUE;
VOID WINAPI ServiceControlHandler(DWORD Opcode);
using namespace std;
VOID WINAPI ServiceControlHandler(DWORD Opcode)
{
PROCESS_INFORMATION pi;
LPWSTR appName = L"cmd.exe";
switch(Opcode)
{
case SERVICE_CONTROL_CUSTOM_MESSAGE:
LaunchAppIntoDifferentSession(appName, &pi);
break;
case SERVICE_CONTROL_PAUSE:
m_ServiceStatus.dwCurrentState = SERVICE_PAUSED;
break;
case SERVICE_CONTROL_CONTINUE:
m_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
break;
case SERVICE_CONTROL_STOP:
m_ServiceStatus.dwWin32ExitCode = 0;
m_ServiceStatus.dwCurrentState = SERVICE_STOPPED;
m_ServiceStatus.dwCheckPoint = 0;
m_ServiceStatus.dwWaitHint = 0;
SetServiceStatus(m_ServiceStatusHandle, &m_ServiceStatus);
bRunning = FALSE;
break;
case SERVICE_CONTROL_INTERROGATE:
break;
return;
}
BOOL LaunchAppIntoDifferentSession(LPWSTR appName,LPPROCESS_INFORMATION pi)
{
STARTUPINFO si;
BOOL bResult = FALSE;
DWORD dwSessionID = 0, winLogonPid = 0, winLogonSessionID = 0, dwCreationFlags;
HANDLE hUserTokenDup, hPToken, hProcess;
dwSessionID = WTSGetActiveConsoleSessionId();
PROCESSENTRY32 procEntry;
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if (hSnap == INVALID_HANDLE_VALUE)return 1;
procEntry.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(hSnap, &procEntry)) return 1;
do
{
if (wcscmp(procEntry.szExeFile,L"winlogon.exe") == 0)
{
ProcessIdToSessionId(procEntry.th32ProcessID, &winLogonSessionID);
if (winLogonSessionID == dwSessionID)
{
winLogonPid = procEntry.th32ProcessID;
}
}
} while (Process32Next(hSnap, &procEntry));
hProcess = OpenProcess(MAXIMUM_ALLOWED,false,winLogonPid);
if (!OpenProcessToken(hProcess,TOKEN_DUPLICATE,&hPToken))
{
CloseHandle(hProcess);
return false;
}
if (!DuplicateTokenEx(hPToken,MAXIMUM_ALLOWED,NULL,SecurityIdentification,TokenPrimary,&hUserTokenDup))
{
CloseHandle(hProcess);
CloseHandle(hPToken);
}
ZeroMemory(&si,sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.lpDesktop = L"winsta0\\default";
dwCreationFlags = NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE;
bResult = CreateProcessAsUser(hUserTokenDup,NULL,appName,NULL,NULL,FALSE,dwCreationFlags,NULL,NULL,&si,pi);
CloseHandle(hProcess);
CloseHandle(hPToken);
CloseHandle(hUserTokenDup);
return bResult;
}
Debuged and found Error is in LaunchAppIntoDifferentSession() only. Now winlogon.exe no more runs in session 0.
Regards,
Vishal
modified on Saturday, August 13, 2011 10:05 PM
|
|
|
|
|
vishalgpt wrote: I found this sample in codeproject.
Then you should post your question in the forum at the end of the article where you found it. That author of the code is the best person to help you.
|
|
|
|
|
i asked it here because since long time the author had not replied to any questions in his article.
Regards,
Vishal
|
|
|
|
|
Your original message gives no clue as to why the code fails; collect some diagnostic information and maybe people will be able to make some suggestions. It may also help if you post a link to the article.
|
|
|
|
|
Subverting Vista UAC in Both 32 and 64 bit Architectures[^]
Service is installed correctly. But when i call the below code in CustomMessageSender.
OpenService(hSCM, SERVICE_NAME,SERVICE_USER_DEFINED_CONTROL);
bSuccess = ControlService(hMyService,SERVICE_CONTROL_CUSTOM_MESSAGE, &status);
bSuccess return TRUE ; But the cmd.exe is not executed as called in LaunchAppIntoDifferentSession()
|
|
|
|
|
Things to consider:
ControlService(hMyService,SERVICE_CONTROL_CUSTOM_MESSAGE, &status);
I presume this line causes ServiceControlHandler() to be called, which in turn calls LaunchAppIntoDifferentSession() which does lots of things, some of which return a result indicating success or failure. Unfortunately these results are not passed back up the line so you have no idea what happened in this function. Add some breakpoints in the LaunchAppIntoDifferentSession() function in order to find out what is happening.
|
|
|
|
|
|
Ooops! There was a small mistake in WTSGetActiveConsoleSessionID() which result in return of Session id to zero only.
Problem solved.
Regards,
Vishal
|
|
|
|
|
|
Hi all,
I am taking a picture control on the dialog.In Properties I am taking a Bitmap Image on the dialog.
I am planning to drag and drop the bitmap image to other location.But i am not able to.
I am able to get the MouseMovements(x axis,y axis),where in ,i am changing the cursor when the mouse is on the
bitmap image as shown in below function.
Please find the below code,which i am trying.
Please let me know what to do
void CLoadImageDlg::OnMouseMove(UINT nFlags, CPoint point)
{
HWND hwnd;
CString str_mousemove;
POINT p;
long int xp,yp,i;
int lParam;
i=3;
GetCursorPos(&p);
xp=p.x;
yp=p.y;
str_mousemove.Format(_T("x = %d,y=%d"),xp,yp);
CPoint ptHotSpot(500,600);
if((xp>507 && xp <696) && (yp>460 && yp<569))
{
SetCapture();
m_bCaptured=TRUE;
CPoint pointTopLeft(507);
m_sizeOffset = point - pointTopLeft;
::SetCursor(::LoadCursor(NULL, IDC_HAND));
}
if((xp<507 ||xp >696) || (yp<460 || yp>569))
{
ReleaseCapture();
}
CDialog::OnMouseMove(nFlags, point);
}
void CLoadImageDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
CString str_mousemove1;
POINT p;
CDC dcMem;
int xp,yp;
GetCursorPos(&p);
xp=p.x;
yp=p.y;
str_mousemove1.Format(_T("x = %d,y=%d"),xp,yp);
if((xp>507 && xp <696) && (yp>460 && yp<569))
{
SetCapture();
m_bCaptured=TRUE;
CPoint pointTopLeft(507);
m_sizeOffset = point - pointTopLeft;
::SetCursor(::LoadCursor(NULL, IDC_HAND));
}
CDialog::OnLButtonDown(nFlags, point);
}
Can anyone please help me,how can i drag the image and drop to other location in the same dialog
Thanks in Advance
Thanks
Sharan
|
|
|
|
|
At a guess you need to implement drag and drop code for your image. Take a look at some of these links[^] for suggestions.
|
|
|
|
|
Hi
I have the following code in a DLL
{
char buffer[30].
WaitForSingleObject
strcpy(command,buffer[0])
when the object gets signaled I get a access exception
because buffer which is a local variable
is refrenced by the stack pointer
any suggestion would be helpfull
thanks
|
|
|
|
|
I'm surprised it even compiled. What you are writing is copying the string to command from the address specified by buffer[0].
strcpy(command, buffer) is probably what you wanted to write.
If that's not the problem, please give the whole code, and use code blocks to properly preserve the format
|
|
|
|
|
What is command and where have you initialized buffer ? Also, on the basis that the above code will not even compile, it is little wonder you are having problems. In future use copy and past to put your code into a question and use the "code block" button to ensure it's formatted properly.
|
|
|
|
|
When I ask what it exactly is, there are always someone told me that the wWinMainCRTStartup is the real entrance of the windows programs. And when you code with UNICODE you should set it with VC++.
I found that this wWinMainCRTStartup function was called before the global object of 'CxxxApp' being constructed. It's called before the programs running.
Can anybody tell what it exactly is? Is it involved with OS or compiler? Where does the Windows programs actually start and how? Or, are there any good books or references to be read for that?
Thanks a lot!
|
|
|
|
|
|