|
Further investigation has shown to me that the problem does not happen always. If I use Process.Start() to open a word or Excel document it does happen but if I open a text file it does not. When the problem occures the following happens:
1) Call Process.Start("somefile.doc");
2) The form receives a Form_Activated() event.
I should tell that the documents are opened via clicking in a treeview in which these files are listed.
I have found "sort of" a solution to the problem which pertains to calling SetForegroundWindow() on the MainWindowHandle of the created process when possible/necessary. Resulting in something like shown below. Sucks big time but it does the trick for now...
[DllImport("user32")]
private static extern IntPtr SetForegroundWindow( IntPtr hWnd );
[DllImport("user32")]
private static extern int GetAsyncKeyState( long vKey );
private void MainForm_Activated(object sender, System.EventArgs e)
{
try
{
if (( GetAsyncKeyState( 0x01 ) & ( 1 << 15 )) == ( 1 << 15 ) ||
( GetAsyncKeyState( 0x02 ) & ( 1 << 15 )) == ( 1 << 15 ) ||
( GetAsyncKeyState( 0x04 ) & ( 1 << 15 )) == ( 1 << 15 ))
{
prProc = null;
}
else if ( prProc != null )
{
if ( prProc.HasExited == false )
SetForegroundWindow( prProc.MainWindowHandle );
prProc = null;
}
}
catch ( InvalidOperationException )
{
}
}
Thanks...
We are the all singing, all dancing crap of the world. - Tyler Durden
|
|
|
|
|
Hi, i'm creating a C# DLL that i access from C++. The C# only connects to the database, creates three arrays, fills them, and passes the filled arrays (int[], double[], string[]) back to C++. The interop appears to be working fine, only my problem is in trying to convert a SAFEARRAY into an int[], double[] and string[] without compromising data integrity. This is my code to do this (at least for just the int[]):
C++:
SAFEARRAY * vi;
SAFEARRAYBOUND rgsaBound[1];
rgsaBound[0].lLbound = 0;
rgsaBound[0].cElements = 100;
vi = SafeArrayCreate(VT_INT, 1, rgsaBound);
spConnNET->Read();//this calls the method in C# to fill the arrays
//the code "spConnNET->ArrayInt()" retrieves the arrays from C#
HRESULT r = SafeArrayAccessData(vi, reinterpret_cast<void**>(spConnNET->ArrayInt()));
It is not changing it from a SAFEARRAY to an integer array though...can anyone tell me what i'm doing wrong, or what needs to be added?
thanks
|
|
|
|
|
just to update: i just changed my code to the following:
C++: (To convert safearray to int[])
//create SAFEARRAY to hold Integers:
SAFEARRAY * holdInt;
//safearray bounds:
SAFEARRAYBOUND bound[1];
bound[0].cElements = 100;
bound[0].lLbound = 0;
holdInt = SafeArrayCreate(VT_I4, 1, bound);
HRESULT r = SafeArrayCopyData(spConnNET->ArrayInt(), holdInt);
LONG pos[1];
LONG hold;
for(int h = 0; h < 100; h++)
{
pos[0] = h;
if (SafeArrayGetElement(holdInt, pos, (void *)&hold) == S_OK)
{
cout << hold << endl;
}
else
{
cout << "something's wrong" << endl;
}
}
Now, it prints out a series of "0's" and i know that's not what the result should be.
|
|
|
|
|
HI all,
I am facing a problem in accessing a VC++ 6.0 ATL COM object via a .Net application
The atl com dll is accessing another dll called OTAClient80.dll
The following piece of code has been written in ATL COM:
/* START OF CODE SNIPPET */
STDMETHODIMP TDDOORSApi::temp(int *count)
{
HRESULT hr = E_FAIL;
::CoInitialize(NULL);
ITDConnection *connect;
HRESULT hr = ::CoCreateInstance(__uuidof(TDConnection), NULL, CLSCTX_INPROC_SERVER, __uuidof(ITDConnection), (LPVOID *)&connect);
if (connect==NULL)
{
return hr;
}
connect->AddRef();
//OTAClient80.dll api
hr=connect->InitConnection("http://PC-P33774/TDBIN","","");//Making a connection to the an application server
if (FAILED(hr))
return hr ;
//OTAClient80.dll api
hr = connect->ConnectProject("TestDirector_Demo","admin",""); //Making a connection to a project on the server
if (FAILED(hr))
return hr;
IRunFactory *runPointer = NULL;
IList *runFieldList = NULL;
//OTAClient80.dll api
hr = connectionPtr->get_RunFactory ((IDispatch**)&runPointer);
//This line gives an exception..
//OTAClient80.dll api
hr = runPointer->get_Fields(&runFieldList);
//Release the connection and dsiconnect from the project
connect->DisconnectProject();
connect->Release();
::CoUninitialize();
return hr;
}
/* END OF CODE SNIPPET */
When I try to invoke this code from a C# windows application or a console application, the line
hr = runPointer->get_Fields(&runFieldList);
gives an exception as follows:
/* START OF EXCEPTION TEXT */
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.Runtime.InteropServices.COMException (0x80010105): The server threw an exception.
at DOORSTDLib.TDDOORSApiClass.temp(Int32& count)
at WindowsApplicationTesting.Form1.button1_Click(Object sender, EventArgs e) in c:\documents and settings\mahendsa\my documents\visual studio projects\windowsapplicationtesting\windowsapplicationtesting\form1.cs:line 123
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/winnt/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
WindowsApplicationTesting
Assembly Version: 1.0.1662.29448
Win32 Version: 1.0.1662.29448
CodeBase: file:///C:/Documents%20and%20Settings/mahendsa/My%20Documents/Visual%20Studio%20Projects/WindowsApplicationTesting/WindowsApplicationTesting/bin/Debug/WindowsApplicationTesting.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/winnt/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/winnt/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
System.Drawing
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/winnt/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
System.Xml
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/winnt/assembly/gac/system.xml/1.0.5000.0__b77a5c561934e089/system.xml.dll
----------------------------------------
Interop.DOORSTDLib
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Documents%20and%20Settings/mahendsa/My%20Documents/Visual%20Studio%20Projects/WindowsApplicationTesting/WindowsApplicationTesting/bin/Debug/Interop.DOORSTDLib.DLL
----------------------------------------
************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitdebugging="true">
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.
---------------------------------------------
/* END OF EXCEPTION TEXT */
Sometimes, I get the error as under:
/* START OF ERROR TEXT */
The value of ESP was not properly saved across function call. This is usually a result of calling a function
declared with one calling convention with a function pointer declared with a different calling convention.
/* END OF ERROR TEXT */
There are no errors if I invoke the dll from an MFC application.
The following is the code invoked from the C# application:
DOORSTDLib.TDDOORSApiClass obj = new TDDOORSApiClass();
obj.temp();
Can someone please throw some light as to where can the problem be / what is the solution?
Regards
Vipul
|
|
|
|
|
Hi,
with VC C# I tried to connect to several webservices through classes generated by wsdl.exe
when I start my app from VS, I always get the error:
- The request failed with HTTP status 503: Service Unavailable -
but when I start the exe (debug or release) from explorer everything works fine !
Any idee how to make debuging work ?
jobr1ch
|
|
|
|
|
Hi,
I've created a Form for generating a receipt print out. The Form has controls aligning with a background image (receipt stencil). To have the Form print correctly, the Form is a little large (1006 x 827). I don't display this Form, it's only for printing (loaded at 0 opacity and closed automatically after printing).
The problem is: If the resolution size of the monitor is smaller than the Form size, the Form is reduced to fit. This mucks up the alignment of the controls to the receipt stencil image. Is there a way to stop this from happening.
Thanks,
Ron
|
|
|
|
|
how about put your form into a small frame(such as panel) with scroll ability.
Alan Shen
MCAD for .NET Version
^~^~^~^~^~^~^~^~^~^~^
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Great idea is the beginging of success!
|
|
|
|
|
Hi,
Do any one know how to freeze some columns in datagrid, like excel does. I would like to see some columns always appear and rest of the columns should appear and disappear with a horizontal scrollbar(like excel freeze).
Thanks in advance.
Sreepathi
|
|
|
|
|
How do I DeSerialize a file in C++ .NET (e.g. using BinaryFormatter) that was originally created by Serialized in an MFC appliction using CDocument::Serialize?
When trying to do this, I get:
BinaryFormatter Version incompatibility. Expected Version 1.0. Received Version 1684632134.539785569.
Thanks!
|
|
|
|
|
I doubt that it's possible this way.
CDocument has one format to serialize data and BinaryFormatter has another one. Just stuffing the output from one class into the other one doesn't work. You'll also fail when you let CDocument deserialize a file created by BinaryFormatter .
Both CDocument and BinaryFormatter write some header information into the target file (or try to read it back in), at least containing some kind of version information, but the structure of this header is different, thus the error.
Besides, IIRC CDocument doesn't add type information to its output but I think BinaryFormatter does (but don't quote me here )
I don't see a chance to achieve this without developing a class to read in a CDocument -generated file manually...
mav
|
|
|
|
|
Does anyone know where I can find articles/code for syntax coloring in .NET?
Happy Programming and may God Bless!
"Your coding practices might be buggy, but your code is always right."
Internet::WWW::CodeProject::bneacetp
|
|
|
|
|
I'm trying to print an HTML file using AxWebBrowser.ExecWB but it it gives a run time error "Trying to revoke a drop target that has not been registered". Does anyone have any suggestions?
axWebBrowser1.QueryStatusWB(SHDocVw.OLECMDID.OLECMDID_PRINT);
object o = "";
SHDocVw.OLECMDID Print = SHDocVw.OLECMDID.OLECMDID_PRINT;
SHDocVw.OLECMDEXECOPT PromptUser = SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER;
axWebBrowser1.ExecWB(Print, DontPromptUser, ref o, ref o);
Thanks.
|
|
|
|
|
Did anyone work with this thing?
Does anyone know if it works with .NET 2.0 beta 1?
(It's a 300MB download, so I would like to know if it works with .NET 2.0 _before_ downloading it? )
Regards,
Serge (Logic Software, Easy Projects .NET site)
|
|
|
|
|
Related to OLE Automation which we used in Visual Studio 6 and earlier versions. I want to know what is the replacement for In-place Activation in .NET environment. I mean how can I make my application to be an OLE Container. Ideas required
Think Negatively, It makes you creative
|
|
|
|
|
There's no simple ole container control in the framework, as far as I know, but using the WebBrowser control to host an OLE object could work.
I found an article on this topic on MSDN.
Regards,
mav
|
|
|
|
|
Thanx mav. This link was really useful
Think Negatively, It makes you creative
|
|
|
|
|
HI~
I use a listview(large icon) of compact framework. After I click a item, it launches to another form with large icon listview.
However, after I launch to another form, all the icons of the previous form in the were disappeared.
How can I solve it?
Thanks
|
|
|
|
|
We are in the initial stage of developing
CE.NET 4.2 (O.S) for Windows Mobile Pocket PC platform using Intel PXA 255 and also PXA 263 chips with subsystems(Bluetooth,WLAN,GSM,GPRS and USB,serial ports) and for using the board in PDA ,which is meant for transmission of emails,integrating with Microsoft Outlook or other Linux tools for the purpose.
If you can develop our solution and quote for the same or alternatively suggest any source who can provide solution for the above requirement, we will be very much obliged.
With regards
K.Sudhhakar Reddy
CEO,OM TELECOMMUNICATIONS
Plot no-98,Phase-1,Kavuri hills,
Madhapur,Hyderabad-500033
India
Tel:0091-040-23112166
Email:omtel@rediffmail.com
omel@rediffmail.com
|
|
|
|
|
lol .... i didn't think India is now outsourcing too I thought all the outsourcing is going to India instead.
|
|
|
|
|
What's puzzling me for a while now is how the RichTextBox behaves when you add text at the end programmatically.
When you have a RichTextBox and call:
richTextBox1.SelectedText += "\nHello World!"; you'd expect it to be the same as calling
richTextBox1.SelectedText += "\n";
richTextBox1.SelectedText += "Hello World!"; wouldn't you?
Now the funny thing is that the first piece of code keeps the current font for "Hello World!" and the second one switches back to the RichTextBox's default font!
Anyone has a faint idea what's going on here or how to keep the RichTextBox from doing this?
mav
|
|
|
|
|
Hi,
I need to make a registry entry for the date of installation. How can I achive this in VS.NET Deployment project?
--
Regards
Vipul Patel
|
|
|
|
|
|
can i use a custom attribute on a method to access and modify parameters and varibles inside a method?
overriding is not applicable in my case
thanks
Mahasen
|
|
|
|
|
ms-help://MS.VSCC.2003/MS.MSDNQTR.2004APR.1033/cpref/html/frlrfsystemattributeclasstopic.htm
This link in MSDN 2003 will help you
M.Sendilkumar
Senior Software Engineer
TVS Infotech
Chennai,TamilNadu,India.
98413 27002
|
|
|
|
|
Hello, I am a newbie in interoperability, and I met a problem with SAFEARRAY in inter-thread communication; unfortunately, I found nothing close to this problem on the Internet.
To summarize:
I have exposed .NET classes to COM clients, one of the classes has an array has returned method value. And in COM (C++) it seems that passing a SAFEARRAY of n "myObject" from a worker thread to a UI thread fails whereas passing n times a single "myObject" works perfectly.
I want to know if something must be done on the c# array which is exposed to COM to solve that.
For those who met this problem (or are courageous), here are the details:
In C#, I have 3 classes "MyObject1","MyObject2" and "MyObject3".
"MyObject1" has a method which returns an array of "MyObject2": public MyObject2[] getArray();
"MyObject2" has a method which returns an instance of "MyObject3": public MyObject3 getObject3();
"MyObject3" has several methods which returns its id, name...
Now, I expose this managed code in a dll to unmanaged code, C++, with .NET framework interop fonctionalities.
In C++, I get:
"MyObject1->getArray()" has a safearray of MyObject2 as returned value
"MyObject2->getObject3()" has MyObject3 as returned value
Great! My managed code is exposed to COM clients!
Now the bug:
In C++, I have 2 threads "UI" and "worker", both are COINIT_APARTMENTTHREADED.
1. I create an instance of "MyObject1" in the UI thread
2. I pass this object to a worker thread method through a queue list
3. In that worker thread method, I call "MyObject1->getArray()" and get the SAFEARRAY of "MyObject2" as returned value
4. I pass back that safearray to a method callback of the UI thread
5. In that UI callback, I want to iterate on the safearray: for each "MyObject2" of the array, I call "MyObject2->getObject3()", then a method of "MyObject3"
-> bug: whatever the method of "MyObject3" which is called, it fails: it seems that "MyObject3" has a problem.
I have made some extra tests:
1. Test1: I put COINIT_MULTITHREADED to UI AND worker: no problem. But this patch cannot be used.
2. Test2: if I do steps 2-to-5 in the worker thread (which means I iterate the safearray in the worker thread, and never go back in the UI): no problem
3. Test3: if I do steps 2-to-5 in the UI thread (which means I never go into worker): no problem
4. Test4:
At step 3, I iterate on the SAFEARRAY. For each "MyObject2" of the array, I pass it to an other callback of the UI. Then, in the UI, I call "MyObject2->getObject3()" and then any methods of "MyObject3", and it is working!
That means that passing a SAFEARRAY of n "MyObject2" from worker to UI fails when we want to retrieve objects from each "MyObject2", but passing n times a single "MyObject2" works perfectly.
I wonder if I have something to add to my C# code so the marshalling/unmarshalling of the array works between threads.
Renaud
|
|
|
|
|