|
thank u very much
I'll try to do it this way
and we will contact if anything goes wrong
thanks
|
|
|
|
|
Hi All,
I want to be able to create an instance of a COM object dynamically, given it's GUID. Having created an instance of the COM object I would like to use reflection to show in a list control the functions that this object exports. I don't want to import the COM object at design time and create a class from it - the COM object is changing regularly, it's a test harness that's being developed concurrently by a set of users.
Is this possible? If so, how do I create the COM object from the GUID only?
Thanks in advance,
Dave Kerr
|
|
|
|
|
Creating the COM object is no problem, but such objects do not support reflection. The only way to get the information you need is through the object's type library. There are a number of COM articles here on CodeProject that include suggestions as to how to proceed with this. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
You can use GetTypeFromCLSID to get a COM Type give its GUID.
Then you can use Activator.CreateInstance to create an object instance from that Type.
|
|
|
|
|
Mirko1980 wrote: Then you can use Activator.CreateInstance to create an object instance from that Type. "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
|
|
|
|
|
Refer also to Richard's answer: I fear you can't get full Reflection information from a COM object.
|
|
|
|
|
Thanks for the info, so as I understand it, I can use Activator.CreateInstance to get the COM object, but I cannot use reflection.
However, can I programmatically load the type library and get the function names from that? Again, I don't want to create a class from the type library, but dynamically retrieve the function names and parameters they take from a type library at runtime...
|
|
|
|
|
DaveKerr wrote: so as I understand it, I can use Activator.CreateInstance to get the COM object, but I cannot use reflection
You can, as long as the component supports IDispatch you can use the CustomMarshaller assembly (you'll commonly find it in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727). The following code sample displays the members of DirControl.DirList.8.0 using reflection:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.CustomMarshalers;
using System.Reflection;
namespace ComMarshaller
{
[
ComImport,
Guid("00020400-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)
]
public interface IDispatch
{
void Reserved();
[PreserveSig]
int GetTypeInfo(uint nInfo, int lcid,
[MarshalAs(
UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(TypeToTypeInfoMarshaler))]
out Type typeInfo);
}
class Program
{
static void Main(string[] args)
{
Type type = Type.GetTypeFromProgID("DirControl.DirList.8.0");
object o = Activator.CreateInstance(type);
IDispatch disp = o as IDispatch;
if (disp != null)
{
Type tp = null;
disp.GetTypeInfo(0, 0, out tp);
MemberInfo[] mi = tp.GetMembers();
foreach (MemberInfo minfo in mi)
{
Console.WriteLine(minfo.Name);
}
}
Console.WriteLine("Done");
Console.ReadKey();
}
}
} Remember, this needs CustomMarshaller.dll added as a reference in your application."WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
extremly sorry, am very new to c# enviornment!
|
|
|
|
|
By using wild card i added an item in Windows context menu of all files now i want to add exception for some files for example i want an option "abc" to show in every files context menu except .jpg files.
can any one guide me how to add this exception and an example would really be appreciated.
thanks in advanceshezi
|
|
|
|
|
hi all
i am trying to convert a excel file data to a dataset using
Microsoft.Office.Interop.Excel.range
anyone know how to do?
i tryed to read the information cell by cell and populate the dataset however it take a very long time.
|
|
|
|
|
you can also do thi without using Microsoft.Office.Interop.Excel.range
just using this
public static DataSet getDataSet(string strFilename)
{
string connstr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\excels\" + strFilename + ";";
connstr += @"Extended Properties=""Excel 12.0;HDR=YES;""";
OleDbConnection conn = new OleDbConnection(connstr);
OleDbCommand cmd = new OleDbCommand("sheet1", conn);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds);
da.Dispose();
conn.Dispose();
cmd.Dispose();
return ds;
}
|
|
|
|
|
I use ClipBoard to copy an image to my application.
I use this code for my application:
if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Bitmap) == true)
{
// Do something
}
I press Ctrl-C on an image, and press Ctrl-V on my application, the code inside if statement doesn't fire.
Can anyone help me on this?
Thanks a lot.
|
|
|
|
|
That IF statement works fine for me when there is a bitmap on the clipboard. Add some more information:
Where are you copying the image from? Does it paste into other applications after you copy it? Where is your IF statement located (in an event handler that intercepts CTRL+V, I would assume)? Have you confired that the code OUTSIDE of the IF statement gets fired?
Post some more code... such as the event handler you are using to capture CTRL+V.
|
|
|
|
|
I copy an image from Window Explorer, or Desktop, and whenever I press Ctrl-V on my application, it does not work as I wish.
It works fine with Microsoft Word.
I catch an event after user clicks Ctrl-V, the code outside IF statement is fired, but not the one inside.
Those are the code that I have done so far:
private void OnKeyDown(Object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.V && e.Modifiers == Keys.Control)
{
// Some code
if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Bitmap) == true)
{
// Do something
}
}
}
Thanks.
|
|
|
|
|
Put a breakpoint on the "if( Clipboard..." line, and see what formats are present.
It may make it easier if you separate the Cliboard.GetDataObject().GetDatePresent(...) into two and examine the Cliboard.GetDataObject() alone.You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
I imagine bitmap is not one of the formats copied when you copy a file. When I tried it, I copied from MS Paint, not from Explorer. I'm pretty sure there is a data format for files/folders... and I think just the path to the file is stored, rather than the file data. In addition to checking for bitmaps, check for files and then you'll have to load the file based on the path.
|
|
|
|
|
highton wrote: I copy an image from Window Explorer, or Desktop
No you didn't, since neither will display an image. You, more than likely, copied a file path that points to an image file to the Clipboard.
|
|
|
|
|
Hi,
then there is no Bitmap format on the Clipboard.
When I copy an image (i.e. an image file) in Windows Explorer, I get 7 data formats on the Clipboard:
[ 0]=Shell IDList Array
[ 1] DataObjectAttributes
[ 2] FileDrop
[ 3] FileName
[ 4] FileNameW
[ 5] Shell Object Offsets
[ 6] Preferred DropEffect
None of them says "Bitmap", which is obvious as Windows Explorer deals with files, not their content. You don't get text when copying a text file, do you?
I suggest you find or build yourself a little utility so you can watch what exactly is on the Clipboard at any time; that is what gave me the above list!
BTW: this is what I get copying from MS Paint:
[ 0]=Embed Source
[ 1] Object Descriptor
[ 2] MetaFilePict
[ 3] DeviceIndependentBitmap
|
|
|
|
|
Hi,
Could you guide me to convert image files(jpeg,bmp,etc..) to PDF files. Thanks in advance.
|
|
|
|
|
|
QuickPDF Library is not a freeware. Could you suggest me a freeware solution
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:32am.
|
|
|
|
|
I just saw PDFSharp here, "Converting Image Files to PDF[^].
Its working for low level dimensional images. But not for higher dimensional image like 3000*3000. The output contains only a part of the image.
Is there any free source code available to convert image to pdf files
|
|
|
|
|
i think you have do some R&D urself, with help of Converting Image Files to PDF[^]. [^]. "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
|
|
|
|