Click here to Skip to main content
15,884,537 members
Home / Discussions / C#
   

C#

 
GeneralRe: control invisible Pin
Dave Kreskowiak6-Apr-13 4:08
mveDave Kreskowiak6-Apr-13 4:08 
GeneralRe: control invisible Pin
cursore848-Apr-13 20:33
cursore848-Apr-13 20:33 
GeneralRe: control invisible Pin
Dave Kreskowiak9-Apr-13 1:05
mveDave Kreskowiak9-Apr-13 1:05 
AnswerRe: control invisible Pin
Boipelo7-Apr-13 15:22
Boipelo7-Apr-13 15:22 
QuestionImproving performance of C# program when run from network drive Pin
eljainc5-Apr-13 5:04
eljainc5-Apr-13 5:04 
AnswerRe: Improving performance of C# program when run from network drive Pin
Dave Kreskowiak5-Apr-13 6:32
mveDave Kreskowiak5-Apr-13 6:32 
AnswerRe: Improving performance of C# program when run from network drive Pin
Jason Gleim5-Apr-13 10:33
professionalJason Gleim5-Apr-13 10:33 
GeneralCast COM object with reflection Pin
Member 99653115-Apr-13 0:04
Member 99653115-Apr-13 0:04 
Hello everybody


I would like to cast a System.__ComObject to another type which is an interface. However, this interface is retrieved by reflection. I tried to create a generic cast method but it failed. I also tried to use TypeConverter class but it also failed. Even now, I try to use Marshal.CreateWrapperOfType but it seems to fail Cry | :((

Here is my code for moment Frown | :(

Assembly ctClientServerLib = Assembly.LoadFrom(string.Concat(bfcSetupFolder, "Interop.CtClientServerLib.dll"));


Type applicationClientClass = ctClientServerLib.GetType("CTCLIENTSERVERLib.CtApplicationClientClass");
Type ictSession = Type.GetTypeFromCLSID(new Guid("BCB06C70-AF26-11D3-8C89-00C04F517D7D"));
Type ictProtectedSession = ctClientServerLib.GetType("CTCLIENTSERVERLib.ICtProtectedSession");
Type ictSessionCtx = Type.GetTypeFromCLSID(new Guid("5F852A70-7E77-11D4-8CE1-00C04F517D7D"));

Type ictSessionClient = Type.GetTypeFromCLSID(new Guid("2C3444F9-ED6D-4700-B2EC-F665569FE830"));
Type ictProviderContainer = Type.GetTypeFromCLSID(new Guid("797BB105-AEDF-11D3-8C89-00C04F517D7D"));
Type ictProviderContainer = Type.GetTypeFromCLSID(new Guid("797BB105-AEDF-11D3-8C89-00C04F517D7D"));

object session;
object res;

res = applicationClientClass.InvokeMember("ConnectToServer", BindingFlags.InvokeMethod, System.Type.DefaultBinder, cacc, new object[] { "MyServer", "MyDataBase", new String[] { } });

session = applicationClientClass.InvokeMember("Logon", BindingFlags.InvokeMethod, System.Type.DefaultBinder, cacc, new object[] { "ADMIN", "" });

res = applicationClientClass.InvokeMember("Initialize", BindingFlags.InvokeMethod, System.Type.DefaultBinder, cacc, new object[] { session });

//I initialize my session and it works fine.

/*Now I need to cast my session (which is an interface called ICtSession)*/

/*ictSession and ictSession is the same interface. I just needed to get type by CLSID for Marshal.CreateWrapperOfType*/
Type ictSession2 = ctClientServerLib.GetType("CTCLIENTSERVERLib.ICtSession");

Type ictSessionCtx2 = ctClientServerLib.GetType("CTCLIENTSERVERLib.ICtSessionCtx");
Type ictSessionClient2 = ctClientServerLib.GetType("CTCLIENTSERVERLib.ICtSessionClient");
Type ictProviderContainer2 = ctClientServerLib.GetType("CTCLIENTSERVERLib.ICtProviderContainer");


var session2 = Marshal.CreateWrapperOfType(session, ictSession);
var sessionClient = Marshal.CreateWrapperOfType(session2, ictSessionClient);
var sessionCtx = Marshal.CreateWrapperOfType(sessionClient, ictSessionCtx);


res = ictSessionCtx2.InvokeMember("SetSessionCtx", BindingFlags.InvokeMethod, System.Type.DefaultBinder, sessionCtx, new object[] { });

var providerContainer = Marshal.CreateWrapperOfType(sessionClient, ictProviderContainer);

/*This method fail !!! I have Exception de HRESULT : 0x80020006 (DISP_E_UNKNOWNNAME)*/
object objectManagerClient = ictProviderContainer2.InvokeMember("get_Provider", BindingFlags.InvokeMethod, System.Type.DefaultBinder, sessionClient, new object[] { 1, -523387 });

/* So I suppose that the cast had failed because I'm sure that ictProviderContainer contains the method get_Provider(int, int) (I checked with ictProviderContainer2.GetMethods()) */.


Thanks for help Java | [Coffee]
GeneralRe: Cast COM object with reflection Pin
BobJanova5-Apr-13 5:12
BobJanova5-Apr-13 5:12 
GeneralRe: Cast COM object with reflection Pin
Member 99653115-Apr-13 5:21
Member 99653115-Apr-13 5:21 
GeneralRe: Cast COM object with reflection Pin
Jason Gleim5-Apr-13 10:51
professionalJason Gleim5-Apr-13 10:51 
GeneralRe: Cast COM object with reflection Pin
Bernhard Hiller7-Apr-13 20:55
Bernhard Hiller7-Apr-13 20:55 
QuestionAbout webcam application Pin
Bishwajit Nepali4-Apr-13 23:56
Bishwajit Nepali4-Apr-13 23:56 
AnswerRe: About webcam application Pin
Abhinav S5-Apr-13 0:47
Abhinav S5-Apr-13 0:47 
QuestionInsert img into sql without using sqlparameter Pin
mohammadkaab4-Apr-13 22:04
mohammadkaab4-Apr-13 22:04 
AnswerRe: Insert img into sql without using sqlparameter Pin
Eddy Vluggen4-Apr-13 22:31
professionalEddy Vluggen4-Apr-13 22:31 
GeneralRe: Insert img into sql without using sqlparameter Pin
mohammadkaab4-Apr-13 22:51
mohammadkaab4-Apr-13 22:51 
AnswerRe: Insert img into sql without using sqlparameter Pin
Eddy Vluggen4-Apr-13 22:55
professionalEddy Vluggen4-Apr-13 22:55 
GeneralRe: Insert img into sql without using sqlparameter Pin
mohammadkaab4-Apr-13 23:05
mohammadkaab4-Apr-13 23:05 
GeneralRe: Insert img into sql without using sqlparameter Pin
Eddy Vluggen5-Apr-13 0:29
professionalEddy Vluggen5-Apr-13 0:29 
GeneralRe: Insert img into sql without using sqlparameter Pin
Richard Deeming5-Apr-13 1:41
mveRichard Deeming5-Apr-13 1:41 
GeneralRe: Insert img into sql without using sqlparameter Pin
BobJanova5-Apr-13 5:15
BobJanova5-Apr-13 5:15 
GeneralRe: Insert img into sql without using sqlparameter Pin
Keith Barrow5-Apr-13 2:44
professionalKeith Barrow5-Apr-13 2:44 
GeneralRe: Insert img into sql without using sqlparameter Pin
Jason Gleim5-Apr-13 11:01
professionalJason Gleim5-Apr-13 11:01 
AnswerRe: Insert img into sql without using sqlparameter Pin
cursore844-Apr-13 23:25
cursore844-Apr-13 23:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.