|
Yeah you are probably right doesn't fit into any of the predefined windows class
I guess if you have a white rectangular background for the arrow you van use bitblt to move it along
|
|
|
|
|
This is a tough one. I have a process running in a console that sometimes "freezes" when trying to read data from serial port (or USB).
The issue only happens if the console does not have focus. If i click on the console so it has focus, the serial data starts coming in again. If the console has focus all the time, the issue never occurs.
It doesn't look like console focus can be detected with SetConsoleCtrlHandler or SetConsoleMode so the question is...
How can a console having focus effect serial port I/O? It doesn't look like a timing issue with console output messages.
|
|
|
|
|
Hi,
No idea if any of this lot is any good, but here are some things I'd try in the same situation:
- Does the slowdown happen with a /subsystem:windows application as well as a console one? If it does then it might be due to threads changing priority when an application is minimised.
- Is your serial I/O code in it's own thread? Normally I wouldn't advocate spinning off threads wily nilly but if the I/O is in it's own thread you don't have to worry about the UI thread being blocked in a message loop somewhere and not able to read from the serial port.
- Does the same thing happen if you run the app as an administrator or ordinary user? If it does there might be a security problem.
- Is there anything else that might be interfering with the serial I/O? Is the COMM port used for anything else or have you several devices on the same USB hub?
Anyway, hope that's not a complete waste of time and there's something in there that might help you resolve your problem,
Cheers,
Ash
|
|
|
|
|
Thanks for the tips. The process is run as Administrator and I just confirmed all reads and writes are from same thread. Not sure about the interals of the USB hub... its an embedded system and serial ports and USB are not standard.
Any more ideas? This is a tough one and has me baffled. Maybe its something in the Windows kernel having to do with handling IO since I don't see a public API to listen to focus events for a console.
|
|
|
|
|
After a little more digging, there was another thread trying to do some occasional writes. The original code had a "read" lock and a "write" lock so it was designed to allow reads and writes at same time but doesn't seem to work reliably unless all I/O is synchronized (one lock for both reads and writes).
|
|
|
|
|
For example, if the user alt-tabs to the window.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
How about WM_ACTIVATEAPP[^] and/or WM_ACTIVATE[^]?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Thanks.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Hi All,
My problem is that the code no longer works under Windows 7/Vista when
called from within the limited user account. CreateFileMapping()
routine returns ERROR_ACCESS_DENIED (code 5) upon attempt to create
the file mapping object in global namespace.
I've searched the web and discovered that from Vista onwards,
Microsoft has changed the policy that affects who will be granted to
obtain SeCreateGlobalPrivilege and that is it impossible for any code
called from within the limited user account to create global objects.
Does anyone know how to work around this limitation? Any pointers on
how to make this code compatible with Windows 7/Vista would be highly
appreciated.
Thanks & Regards,
Uday.
|
|
|
|
|
Hello,
I have an application that import contacts from outlook contact directory.
there is a problem that when someone has a very big list of contacts the application get stuck for along time until it finish importing the contacts,
I moved the entire import code to a pthread that will handle the import so the application won't get stuck while it's importing.
to access outlook i'm using this code:
hr=pApp.CreateInstance(__uuidof(Application));
when this code is executed from within a pthread it fails, but when executed normally from the application everything is working fine,
Anyone know what causing this problem?
Thanks.
|
|
|
|
|
Does that CreateInstance require you to initialize COM before using it (CoInitialize/CoInitializeEx)? If yes, how did you initialize it?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
No initialize is needed,
here is the code access the outlook:
void CXPowerUIView::importFromOutlook()
{
_ApplicationPtr pApp;
_ItemsPtr pItems;
MAPIFolderPtr pFolder;
_ContactItemPtr pContact;
HRESULT hr;
try
{
hr=pApp.CreateInstance(__uuidof(Application));
if (FAILED(hr))
{
MessageBox(_T("Unable to instantiate Outlook."),_T("Outlook Error"),MB_OK);
return;
}
...........
}
This are the 2 ways I call it:
direct:
importFromOutlook();
from thread:
outlookHandle = CreateEvent(NULL, FALSE, FALSE, NULL);
outlookImportThread = ys_thread_create(2000, OutlookThreadFunc, NULL);
void* OutlookThreadFunc(void* pParam)
{
pThisView->importFromOutlook();
return NULL;
}
only direct one is working :/
|
|
|
|
|
And what does the HRESULT hr tell you? Just a blindshot here, add this to your thread:
CoInitializeex(NULL, COINIT_MULTITHREADED); at the beginning and CoUninitialize at the end. Like:
void* OutlookThreadFunc(void* pParam)
{
CoInitializeEx(NULL, COINIT_MULTITHREADED);
pThisView->importFromOutlook();
CoUninitialize();
return NULL;
}
That _ApplicationPtr::CreateInstance is probably using COM and as far as i know you have to initialize COM in every thread you intend to use it in.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
|
Hi,
I am working on Excel Automation Project.
using GetActiveobject , getting one instance of Excel.exe. But need to track/access any number of instances which are opened.
Initally I am checking all the processes in task manager, if Excel.exe is running, then I will loop through to get the active Excel object using GetActiveObject.
But only one instance I am able to access. How to track other instance of Excel.exe's.
Regards,
KTTransfer.
|
|
|
|
|
This code by a coder dude called NarVish gets the Windows Handles
from process id of excel instance instances.
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
DWORD dwThreadId, dwProcessId;
HINSTANCE hInstance;
char String[255];
HANDLE hProcess;
dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId);
}
int _tmain(int argc, _TCHAR* argv[])
{
HWND hwnd = (HWND)FindWindow(_T("XLMAIN"), NULL);
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
if( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return 1;
cProcesses = cbNeeded / sizeof(DWORD);
for (i=0; i<cProcesses; i++ )
{
if( aProcesses[i] != 0 )
{
TCHAR szProcessName[MAX_PATH] = _T("<unknown>");
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, aProcesses[i] );
if ( NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if( EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName)/sizeof(TCHAR) );
if(_wcsicmp(szProcessName,L"EXCEL.EXE") == 0)
{
cout<< szProcessName << "--" << aProcesses[i] <<endl;
Excel::Window* pWindow = NULL;
pid = aProcesses[i];
EnumWindows( EnumWindowsProc, NULL);
HRESULT hr = AccessibleObjectFromWindow(hwnd, OBJID_NATIVEOM, __uuidof(Excel::Window), (void**)&pWindow);
if (hr == S_OK)
{
}
}
}
}
_tprintf( TEXT("%s (PID: %u)\n"), szProcessName, aProcesses[i] );
CloseHandle( hProcess );
}
}
return 0;
}
|
|
|
|
|
Do you need the COM instances or just the process handles?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
I need COM instance.
Excel::_ApplicationPtr.
|
|
|
|
|
This code might help you. Call get_Application function of the obtained document IDispatch to get its application's IDispatch.
void COffCntrDispCtrl::GetDocDispatch()
{
if(m_pDocDisp != NULL) return;
IBindCtx *pbc;
HRESULT hr = CreateBindCtx(0, &pbc);
if(FAILED(hr)) {
DoErr("CreateBindCtx()", hr);
return;
}
IRunningObjectTable *prot;
hr = pbc->GetRunningObjectTable(&prot);
if(FAILED(hr)) {
DoErr("GetRunningObjectTable()", hr);
pbc->Release();
return;
}
IEnumMoniker *pem;
hr = prot->EnumRunning(&pem);
if(FAILED(hr)) {
DoErr("EnumRunning()", hr);
prot->Release();
pbc->Release();
return;
}
pem->Reset();
ULONG fetched;
IMoniker *pmon;
int n = 0;
while(pem->Next(1, &pmon, &fetched) == S_OK) {
LPOLESTR pName;
pmon->GetDisplayName(pbc, NULL, &pName);
char szName[512];
WideCharToMultiByte(CP_ACP, 0, pName, -1, szName, 512, NULL,
NULL);
if(!strcmp(szName, m_szDocName)) {
DoMsg("Found document in ROT!");
IDispatch *pDisp;
hr = pmon->BindToObject(pbc, NULL, IID_IDispatch, (void
**)&pDisp);
if(!FAILED(hr)) {
m_pDocDisp = pDisp;
sprintf(buf, "Document IDispatch = %08lx",
m_pDocDisp);
DoMsg(buf);
}
else {
DoErr("BindToObject()", hr);
}
}
pmon->Release();
if(m_pDocDisp != NULL) break;
}
pem->Release();
prot->Release();
pbc->Release();
}
void COffCntrDispCtrl::TestDispatch()
{
ASSERT(m_pDocDisp);
COleDispatchDriver doc(m_pDocDisp);
DISPID dispID = 0;
unsigned short *ucPtr = L"Name";
HRESULT hr = m_pDocDisp->GetIDsOfNames(IID_NULL, &ucPtr, 1,
LOCALE_USER_DEFAULT, &dispID);
ASSERT(!FAILED(hr));
CString name;
doc.GetProperty(dispID, VT_BSTR, &name);
AfxMessageBox(
CString("Document name is ") + name,
MB_SETFOREGROUND
);
}
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
I am working on a similar problem. I know the HWND for each Excel instance and implemented the MFC ActiveX control you mention above. However, I have not used an ActiveX control in C++ before. Do you know how I can get m_pDocDisp? I tried putting just the code above in my native C++ / Excel C API application and it doesn't find it.
http://www.codeproject.com/Messages/3730176/Get-Document-IDispatch-in-native-Cplusplus-possibl.aspx
|
|
|
|
|
Hi All,
I have an application generated by the VS2005 AppWizard so that it has Automation enabled and I've setup the interface so it all works correctly.
However, I also have the app accepting command line parameters when starting from the command line(which it mainly is since it's fired up from a Java servlet).
The app gets called so many times I only want one instance of it to exist at a time so as to cut down on system resource usage.
What I want to do is register the IDispatch of the automation object with the ROT when the app is first started up with the command line. That way when a user starts the app again I can check with the ROT to see if an instance of my app is running. If it is, I just get the IDispatch out of the ROT and pass the parameter values to the running instance via the methods on it. I then shut down my app before I've completed assigning all the necessary resources to it.
So my question is: How do I get the IDispatch to my app if it has been started with the command line?
Thanks very much for any help
Thomas
Cheers
Tom
Philosophy: The art of never getting beyond the concept of life.
Religion: Morality taking credit for the work of luck.
|
|
|
|
|
hello guys i need a project or rich examples for my projects ,and i have to deliver it this Thursday
and thank you very much
|
|
|
|
|
Wrong forum.
Be more specific and post to C++ CLI forum.
Life is a stage and we are all actors!
|
|
|
|
|
alright
i am on my way
|
|
|
|
|
Hi,
I have single Dialog Templates with all controls using for 3 differnt types.
For Controller-EditBox should be shown
For Indicator-ComboBox should be shown
For Switch-RadioButton should be shown.
So when i invoke dialog for controller it will show editbox,indicator will show combobox .
And What i want, if i invoke controller,then i will invoke indicator without closing the controller.
THis is funcntinality i want.
But what happened,after i clicked controller,when i click indicator it shows edit box only not ComBobox.
If i first open indicator,and then controller shows only ComboBox not EditBox.
How can i get that.
I use UpdateData() in OnInitDialog,But no use.
BOOL CFacePlate::OnInitDialog()
{
CDialog::OnInitDialog();
UpdateData(FALSE);
if(oTagBase->GetTagType()==CONTROLLER)
{
GetDlgItem(IDC_STATECOMBO)->ShowWindow(SW_HIDE);
}
if(oTagBase->GetTagType()==INDICATOR)
{
GetDlgItem(IDC_SPVALUE)->ShowWindow(SW_HIDE);
}
I have lot of controls like this.So i coded only to hide controls and not to show.
Is there any solution?
Anu
|
|
|
|
|