Click here to Skip to main content
15,892,927 members
Home / Discussions / C#
   

C#

 
AnswerRe: Creating a file and saving it to C Pin
harold aptroot6-Apr-10 15:03
harold aptroot6-Apr-10 15:03 
GeneralRe: Creating a file and saving it to C Pin
Darrall6-Apr-10 15:47
Darrall6-Apr-10 15:47 
GeneralRe: Creating a file and saving it to C Pin
Dan Mos6-Apr-10 16:49
Dan Mos6-Apr-10 16:49 
GeneralRe: Creating a file and saving it to C Pin
Darrall7-Apr-10 4:47
Darrall7-Apr-10 4:47 
AnswerRe: Creating a file and saving it to C Pin
PIEBALDconsult6-Apr-10 15:24
mvePIEBALDconsult6-Apr-10 15:24 
GeneralRe: Creating a file and saving it to C Pin
Darrall6-Apr-10 16:01
Darrall6-Apr-10 16:01 
GeneralRe: Creating a file and saving it to C Pin
PIEBALDconsult6-Apr-10 16:13
mvePIEBALDconsult6-Apr-10 16:13 
QuestionHow to call a COM function with arguments using IDispatch in C# Pin
JF Pomerleau6-Apr-10 11:27
JF Pomerleau6-Apr-10 11:27 
Hello everyone,

I need to call a function that needs arguments from a COM object using the IDispatch interface. I have been able to call functions that does not need parameters and to get values from properties of the COM object using the Invoke function of the IDispatch interface. However, I am unable to call a function with parameter using the Invoke function of IDispatch. I believe it is because I don't set in the proper way the value "rgvarg" of the DISPPARAMS structure that must be passed to the invoke function to represent the arguments that must be passed to the object function. DISPPARAMS.rgvarg is expecting a IntPtr that represent an array of objects.

Does anyone have done this?

Here is a sample code of my program.

Type tSWApp = Type.GetTypeFromProgID("SldWorks.Application");
object swApp = Activator.CreateInstance(tSWApp);
IDispatch idisp = (IDispatch)swApp;

// Getting the visible property (this part works)
Guid guid = new Guid();
int[] nIds = new int[] { 0 };
nRetVal = idisp.GetIDsOfNames(ref guid, new string[] { "Visible" }, 1, 0, nIds);

DISPPARAMS dispParams = new DISPPARAMS();
dispParams.cArgs = 0;
dispParams.cNamedArgs = 0;
object pVarResult;

System.Runtime.InteropServices.ComTypes.EXCEPINFO excepInfo = new System.Runtime.InteropServices.ComTypes.EXCEPINFO();

nRetVal = idisp.Invoke(nIds[0], ref guid, 0, (ushort)System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_PROPERTYGET, ref dispParams, out pVarResult, ref excepInfo, null);

// Launching a function with parameters
object[] oArgs = new object[]{ 10 };
nRetVal = idisp.GetIDsOfNames(ref guid, new string[] { "GetUserPreferenceIntegerValue" }, 1, 0, nIds);
dispParams.cArgs = 1;
--> dispParams.rgvarg = ???; <-- Here, I must provide a IntPtr object that represent the array "oArgs" defined above.
dispParams.cNamedArgs = 0;
dispParams.rgdispidNamedArgs = new object[] { };
nRetVal = idisp.Invoke(nIds[0], ref guid, 0, (ushort)System.Runtime.InteropServices.ComTypes.INVOKEKIND.INVOKE_FUNC, ref dispParams, out pVarResult, ref excepInfo, null);


Thanks!
AnswerRe: How to call a COM function with arguments using IDispatch in C# Pin
chrismisztur15-Jun-10 11:01
chrismisztur15-Jun-10 11:01 
Questiontips on windows application running on a local server Pin
mrkeivan6-Apr-10 7:33
mrkeivan6-Apr-10 7:33 
AnswerRe: tips on windows application running on a local server Pin
Not Active6-Apr-10 8:48
mentorNot Active6-Apr-10 8:48 
AnswerRe: tips on windows application running on a local server Pin
Dave Kreskowiak6-Apr-10 9:58
mveDave Kreskowiak6-Apr-10 9:58 
GeneralRe: tips on windows application running on a local server Pin
mrkeivan6-Apr-10 18:31
mrkeivan6-Apr-10 18:31 
AnswerRe: tips on windows application running on a local server Pin
PIEBALDconsult6-Apr-10 11:43
mvePIEBALDconsult6-Apr-10 11:43 
Questiondatagridview Pin
hamid53056-Apr-10 6:45
hamid53056-Apr-10 6:45 
AnswerRe: datagridview Pin
RCoate6-Apr-10 13:15
RCoate6-Apr-10 13:15 
Questioni am getting an error in C#. Pin
amitk_1896-Apr-10 6:17
amitk_1896-Apr-10 6:17 
AnswerRe: i am getting an error in C#. PinPopular
Not Active6-Apr-10 6:22
mentorNot Active6-Apr-10 6:22 
QuestionReverse tab in a TextBox. Pin
x3mjeff6-Apr-10 5:08
x3mjeff6-Apr-10 5:08 
AnswerRe: Reverse tab in a TextBox. Pin
OriginalGriff6-Apr-10 5:20
mveOriginalGriff6-Apr-10 5:20 
AnswerRe: Reverse tab in a TextBox. Pin
x3mjeff6-Apr-10 5:32
x3mjeff6-Apr-10 5:32 
GeneralRe: Reverse tab in a TextBox. Pin
OriginalGriff6-Apr-10 6:08
mveOriginalGriff6-Apr-10 6:08 
GeneralRe: Reverse tab in a TextBox. Pin
Nitin S6-Apr-10 5:44
professionalNitin S6-Apr-10 5:44 
AnswerRe: Reverse tab in a TextBox. Pin
AspDotNetDev6-Apr-10 12:22
protectorAspDotNetDev6-Apr-10 12:22 
QuestionAccepting file via CGI POST? Pin
DaveKub6-Apr-10 4:58
DaveKub6-Apr-10 4:58 

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.