.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How can I pass a NULL value as [in,out] argument to a COM method using late binding?

Posted By:      Posted Date: October 12, 2010    Points: 0   Category :.NET Framework

Suppose I have the following method in a COM interface defined in a C++ IDL:

[id(8)] HRESULT MyMethod([in,out,defaultvalue(NULL)] LONG* value, [out, retval] BSTR* returnValue);

Now I want to call this method passing in NULL for the 'value' parameter using late binding in C#. How can this be accomplished?

The following works if I want to pass a non-null argument as value:

         Type type = Type.GetTypeFromCLSID(new Guid("{7DA7BD6A-3E11-4E6B-BDE3-7C968A085F94}"));
         object instance = Activator.CreateInstance(type);

         object[] arguments = new object[] { 101 };

         ParameterModifier modifier = new ParameterModifier(1);

         modifier[0] = true;

         type.InvokeMember("[DispID=8]", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, instance, arguments, new ParameterModifier[] { modifier }, null, null);

         Console.WriteLine("Value after call: {0}", arguments[0]);

But how can I pass NULL? Using 'null' or Type.Missing give me type

View Complete Post

More Related Resource Links

Binding an event method from a control in a seperate window

How would you bind a event method from a control back to a seperate window?  I have a ActiveX control hosted in a WindowsFormsIntegration wrapper.  That is operating in its own window along with all its events.  The properties of the control are handled by a class that defines the dependency objects (thanks Bob) to provide a view model between it and a window with controls for setting/getting those properties.  Since events constrained to Window 2, is it possible to bind the events back to Window 1?

How to Pass higher Length of Byte Array to the remoting method

Dear all,I am using a windows application and the businness logic is present in the remote server.Once particular method takes bytearray as input parameter...Whenever the method call is made the function returns value .This is limited for the particular bytearray length. (4109228 bytes).If the length of bytearray crosses 4109228 bytes.I am getting an error that "input stream is not valid binary format".How to Pass higher Length of Byte Array to the remoting method... Greater than 4 MB?I believe something is missing in web.config or app.config...?What could be the issue...? Any sugesstions are welcome....ThanksRavikumar

Capture and pass "abc\xyz" as a string into my WCF method

Hi All, I am trying to implement WCF Method where client has to pass like "abc\xyz" as a string i have to capture it and pass to my method. I am not able to do it. In our application we can split the string  and we can do what ever we can do . but string comes from client site so who do i capture into my method. I am very much new in WCF. Could u please help me. Thanks Shekhar  

How to pass parameters from Application Main method to modules.

Hi , We created Prism WPF application.we have to pass some parameters(some information) to modules(they are instantiated by Bootstrapper) from Main method of App.xaml  Thanks in Advance.

How to set and map a Method in the Service file with endpoint elements and binding elements

Hi all, I have created a service file like OSService.svc in that i have two methods like one is FileUpload and FileDownload for e.g :- [WebInvoke(UriTemplate = "/fileupload/{fileName}" , Method = "POST" )]         [OperationContract]         void FileUpload(string fileName, Stream fileContents); same as Filedownload also. People you may know these methods are inside the interface of service file what you are using i'e i have created a interface as IOSService.cs. So, what i need now is i want to write separate endpoint for FileUpload and Filedownload.Because i want to set separate value for receiveTimeout  and openTimeout for the Fileupload and FileDownload process in binding section in the web.config file itself. The below code was i'm using right now but still i'm not able to the set separate value of endpoint elements in the bindings. EndPoint Section:- <endpoint name = "endPoint1"  address  = "localhost:8000/OSService.svc/" bindingConfiguration = "TransactionalTCP"   binding  = "netTcpBinding"          contract = "IOSService"/> Binding Section:-  <binding name = "TransactionalTCP"  transactionFlow = "true"   /&

WCF Basic Http Binding - Two server requests per method call

We have a service that uses BasicHttpBinding/Transport Security/Windows Authentication and is hosted in IIS. I have created a unit-test application in VSTS and whenever we test a WCF method, Fiddler records two calls. 1st call - No authorization token is sent. The WCF service returns a 401 error - Unauthorized: Access is denied. Http headers as sent in the request given below. POST http://localhost/AccountScreen.svc HTTP/1.1 Content-Type: text/xml; charset=utf-8 SOAPAction: "IAccountScreen/RetrieveAccountDetails" Host: localhost Content-Length: 243 Expect: 100-continue Connection: Keep-Alive 2nd call - Authorization token is sent and the WCF service returns the expected response. POST http://localhost/AccountScreen.svc HTTP/1.1 Content-Type: text/xml; charset=utf-8 SOAPAction: "IAccountScreen/RetrieveAccountDetails" Authorization: Negotiate Host: localhost Content-Length: 243 Expect: 100-continue I am not able to figure out why there are two calls made to the server in the first place and what is the significance of the first call. Any thoughts?

Early Late binding & Polymorphism question

Hi,I read this online about early & late binding.. I don't understand (the example below) how it is, can anyone explain why?Early binding:: Properties and method can be identified by compile time.Example: dim rs as recordsetLate binnding: Properties and method can be identified by Run time.Example: dim obj as classnameset obj=new classnamePolymorphism:Also, why the reason they are said Method overloading & OverridingExample of Compile Time Polymorphism: Method OverloadingExample of Run Time Polymorphism: Method OverridingCan anyone explain the logic behind these two? Thanks in advanceThanks

Need help with late binding on bindingsource field

This is an error that popped up with after setting option strict to on   option strict disallows late binding   The error is on the field in red If customer_data_reader("CustID") = (customer_bindingsource.Current("CustID") Then          i was looking at this but i cannot find what type this is exactly   If CStr(customer_data_reader("CustID")) = Ctype(customer_bindingsource.Current("CustID"), ????????) Then      It is a field, but how would i set the type for this? Or do i need to do something different?   Thanks Jeff

arguments null in onSuccess method

HiI'm trying to validate user input into a textbox via a web service.I'm using a Dynamic Data site, with a custom Dynamic Data field to show this particular value. In the dynamic data field I've added a custom validator - <asp:CustomValidator id="CustomValidator1" runat="server"        ErrorMessage="Invalid Item ID!"      ControlToValidate="TextBox1"      OnServerValidate="ServerValidate"      ClientValidationFunction="validateItem"     /><asp:CustomValidator id="CustomValidator1" runat="server" ErrorMessage="Invalid Item ID!" ControlToValidate="TextBox1" OnServerValidate="ServerValidate" ClientValidationFunction="validateItem" />In a custom page, I have the following Javascript - <script type="text/javascript"> <!-- function validateItem(source, arguments) { InventTableService.exists(arguments.Value, onComplete, onError); } function onComplete(source, arguments) { alert(source); arguments.IsValid = source; }

Click.CommandParameter null when binding on Button inside DataGrid DataGridTemplateColumn

I am having trouble getting a Click.CommandParameter to pass through with a bound Click.Command. I have a DataGrid with a DataGridTemplateColumn that contains a couple of Buttons. Using a suggestion found on the forum (http://social.msdn.microsoft.com/Forums/en/wpf/thread/541024a9-3d7e-4c6a-b88e-9a7eb7ee83a9), I was able to get the Click.Command to bind to the right command, but when arriving in the corresponding method in my ViewModel, the parameter is null.  Here is my xaml for my DataGridTemplateColumn <data:DataGridTemplateColumn Header="Case">  <data:DataGridTemplateColumn.CellTemplate>   <DataTemplate >    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">     <Button Content="Open" Margin="6,0" command:Click.Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type data:DataGrid}}, Path=DataContext.OpenCaseCommand}" CommandParameter="{Binding}"  />     <Path Data="M1,1 L1,2" Stroke="#FFCCCCCC"/>     <Button Content="Rename" />    </StackPanel>   </DataTemplate>  </data:DataGridTemplateColumn.CellTemplate> </data:DataGridTemplateColumn> I used Snoop to see what was going on. Everything

pass a dynamic parameter in a WCF method on HTTP GET


i have a WCF method with 2 known parameters and another one thats supposed to include a Key:Value pairs (dynamic parameter that will include an unknown number of key:value pairs).

the first question is :

i don't want to use XML as the dynamic parameter. what is the common way to pass the dynamic parameter in a WCF method? Dictionary<string,String>? json string? array of complex types? or other? ( my client - the one that uses my service, doesn't have Framework 3.5, so i suggested a framework 2.0 ways to send the parameter)

the second question :

the method  supports HTTP GET , should a dynamic parameter be passed in the URL itself or in the Header? i prefer the URL itself....


thank guys, please help ....

How to pass argument to javascript function



in aspx page i have taken a simple html anchor tag like this:

<a id="l1" href="javascript:OnLookup();">Click</a>

when "Click" is clicked, that OnLookup function is called. But if i want to pass argument in that function then how can i pass ?

This anchor tag is generated dynamically through another javascript function.There can be more than one anchor tags, and each having different arguments in OnLookup function call .

How can pass arguments dynamically ?

binding null to calendar


The following code gives error: "When casting from a number, the value must be a number less than infinity."

<asp:TemplateField HeaderText="DATE" SortExpression="date1">
                            <asp:Calendar ID="Calendar1" runat="server"
                                    SelectedDate='<%# Bind("date1") %>' VisibleDate='<%# Eval("date1") %>'>

Pass delivery method, email address to create SSRS subscription using VS2005



I have created SSRS reports and built a user UI to run these reports. Now when creating SSRS subscriptions in report Manager, is it even possible to programmatically pass the delivery method (email or file share), To email address, scheduled time and date, etc from my front-end UI to the Report Manager?

Any help will be greatly appreciated. Thanks

Sending JSON Array to an ASP.NET MVC Action Method Argument


 <input type = "submit" onclick = "savePayment()"  value = "Test"/>

    <script type="text/javascript">
        function savePayment() {
            //Creating some test data
            var lineItems = new Object();
            lineItems.Entrys = new Array();
            lineItems.Entrys[0] = new Object({ Name: "Dung", Age: "21"});
            lineItems.Entrys[1] = new Object({ Name: "An", Age: "25" });

            //Posting them to server with ajax
                type: 'POST',
                contentType: 'application/json; charset=utf-8',
                url: '<%=Url.Action("TestArray", "Json") %>',
                dataType: 'json',
                data: $.toJSON(lineItems),
                success: function (result) {
                    if (result) {
                    else {

BDC Models - Pass parameters to ReadList() method?


Hi Guys,

I have some BDC models built and they work great within Sharepoint. I have one list, for example, which lists all Institutions listed in the DB.
On the following page (Everything you need to know about BDC) they show a customers list with search options at the top of it. Is it possible to get that working in Visual Studio? I've tried using filters, but it appears as those values are hard-coded from the List Settings page.
Any thoughts on how to achieve something similar?

Next challenge is to figure out how to get one-to-many relations ships working for reading data, and then for writing data (an institution can have multiple addresses, for example). But that's for another day :)


I wrote a book :) http://www.amazon.com/Microsoft-Visual-Studio-2008-Programming/dp/0071604081

GetUserProfileByName method in userprofileservice.asmx returns null values when used in Service Refe


I'm using Silverlight 4 to call GetUserProfileByName method of the SharePoint 2007 userprofileservice.asmx web service. For each of the PropertyData in the e.Result object that is returned, the Values array is null.

Below is the Completed event handler. Execution gets inside the if block for each of the PropertyData.


void client_GetUserProfileByNameCompleted(object sender, GetUserProfileByNameCompletedEventArgs e)
 foreach (PropertyData prop in e.Result)
  if (prop.Values == null) // this is ALWAYS true for each prop


After some investigation, I've found out this only happens when userprofileservice.asmx is added as a Service Reference. I tested this out by creating an ASP.NET project. In it I added userprofileservice.asmx as a Web Reference, and then as a Service Reference. For the Web Reference case,
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend