Search Results

Search found 1919 results on 77 pages for 'typeof'.

Page 17/77 | < Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >

  • Abstract Factory Using Generics: Is Explicitly Converting a Specified Type to Generic a Bad Practice

    - by Merritt
    The question's title says it all. I like how it fits into the rest of my code, but does it smell? public interface IFoo<T> { T Bar { get; set; } } public class StringFoo : IFoo<string> { public string Bar { get; set; } } public static class FooFactory { public static IFoo<T> CreateFoo<T>() { if (typeof(T) == typeof(string)) { return new StringFoo() as IFoo<T>; } throw new NotImplementedException(); } } UPDATE: this is sort of a duplicate of Is the StaticFactory in codecampserver a well known pattern?

    Read the article

  • Trouble Emitting Object Array using Reflection.Emit

    - by JoeGeeky
    I am trying to Emit what I thought would be a simple object array that would result in code similar to the below example object[] parameters = new object[] { a, b, }; When I write the above code in C# using VS, I get the following IL. As expected this works. .locals init ( [0] object[] parameters, [1] object[] CS$0$0000) However, when I try and Emit IL directly, I only ever get a one index init array. Can someone help tell me where I've gone wrong here? Here is the Emit code I'm using: int arraySize = 2; LocalBuilder paramValues = ilGenerator.DeclareLocal(typeof(object[])); paramValues.SetLocalSymInfo("parameters"); ilGenerator.Emit(OpCodes.Ldc_I4_S, arraySize); ilGenerator.Emit(OpCodes.Newarr, typeof(object)); ilGenerator.Emit(OpCodes.Stloc, paramValues); Here is the resulting IL: .locals init ( [0] object[] objArray) The rest of the resulting IL is identical between the two solutions, but for some reason the .locals init is different.

    Read the article

  • NHibernate.Linq to Criteria API translation help needed

    - by Arnis L.
    I'm not sure how to add paging to this: Session.Linq<Article>() .Where(art => art.Tags.Any(t => t.Name == tag)).ToList(). So i decided to use Criteria API. var rowCount = Session.CreateCriteria(typeof(Article)) .SetProjection(Projections.RowCount()).FutureValue<Int32>(); var res = Session.CreateCriteria(typeof(Article)) .Add(/* any help with this? :) */) .SetFirstResult(page * pageSize) .SetMaxResults(pageSize) .AddOrder(new Order("DatePublish", true)) .Future<Article>(); totalCount = rowCount.Value; Any help appreciated.

    Read the article

  • Reflection.Emit: How to convert MethodBuilder to RuntimeMethodInfo reliably?

    - by Qwertie
    After generating a type dynamically and calling TypeBuilder.CreateType, I want to create a delegate that points to a method in the new type. But if I use code like loadedType = typeBuilder.CreateType(); myDelegate = (MyDelegate)Delegate.CreateDelegate( typeof(MyDelegate), methodBuilder); Reusing the methodBuilder as a methodInfo, I get the exception "MethodInfo must be a RuntimeMethodInfo". Now normally I can re-acquire the MethodInfo with MethodInfo mi = loadedType.GetMethod(methodBuilder.Name); myDelegate = (MyDelegate)Delegate.CreateDelegate(typeof(MyDelegate), mi); But my class may contain several overloaded methods with the same name. How do I make sure I get the right one? Do methods have some persistent identifier I could look up in loadedType?

    Read the article

  • Setting a "dependency property" in code

    - by Matt B
    I'm on a roll today... I have the following code delaring a dependency property inside a class called ActionScreen: #region Dependency Properties & Methods public string DescriptionHeader { get { return (string)GetValue(DescriptionHeaderProperty); } set { SetValue(DescriptionHeaderProperty, value); } } // Using a DependencyProperty as the backing store for DescriptionHeader. This enables animation, styling, binding, etc... public static readonly DependencyProperty DescriptionHeaderProperty = DependencyProperty.Register("DescriptionHeader", typeof(string), typeof(ActionScreen), new UIPropertyMetadata("xxx")); #endregion I bind to this property in my Xaml as so: <GridViewColumn DisplayMemberBinding="{Binding Description}" Header="{Binding DescriptionHeader}" Width="350" /> Now I want to be able to set the parameter from my code behind when I recieve an event - but it's not working: public string DescColText { set { this.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate() { DescriptionHeader = value; })); } }

    Read the article

  • Is this a correct way to host a WCF service?

    - by mafutrct
    For some testing code, I'd like to be able to host a WCF service in only a few lines. I figured I'd write a simple hosting class: public class WcfHost : IDisposable where Implementation : class where Contract : class { public readonly string Address = "net.tcp://localhost:8000/"; private ServiceHost _Host; public WcfHost () { _Host = new ServiceHost (typeof (Implementation)); var binding = new NetTcpBinding (); var address = new Uri (Address); _Host.AddServiceEndpoint ( typeof (Contract), binding, address); _Host.Open (); } public void Dispose () { ((IDisposable) _Host).Dispose (); } } That can be used like this: using (var host = new WcfHost<ImplementationClass, ContractClass> ()) { Is there anything wrong with this approach? Is there a flaw in the code (esp. about the disposing)?

    Read the article

  • How do I convert a System.Type to its nullable version?

    - by AlexDuggleby
    Once again one of those: "Is there an easier built-in way of doing things instead of my helper method?" So it's easy to get the underlying type from a nullable type, but how do I get the nullable version of a .NET type? So I have typeof(int) typeof(DateTime) System.Type t = something; and I want int? DateTime? or Nullable<int> (which is the same) if t is primitive then Nullable<T> else just T Any suggestions? (Is there something built in.) Thanks in advance.

    Read the article

  • How to validate Data Annotations with a MetaData class

    - by Micah
    I'm trying to validate a class using Data Annotations but with a metadata class. [MetadataType(typeof(TestMetaData))] public class Test { public string Prop { get; set; } internal class TestMetaData { [Required] public string Prop { get; set; } } } [Test] [ExpectedException(typeof(ValidationException))] public void TestIt() { var invalidObject = new Test(); var context = new ValidationContext(invalidObject, null, null); context.MemberName = "Prop"; Validator.ValidateProperty(invalidObject.Prop, context); } The test fails. If I ditch the metadata class and just decorated the property on the actual class it works fine. WTH am I doing wrong? This is putting me on the verge of insanity. Please help.

    Read the article

  • CodeContracts: ccrewrite fails with Object reference not set to an instance of an object

    - by Vyas Bharghava
    The below code makes ccrewrite blow up! Ideas? BTW, If you comment out the ActualClass, ccrewrite succeeds... [ContractClass(typeof(TestContracts))] interface ITestInterface { bool IsStarted { get; set; } void Begin(); } class ActualClass : ITestInterface { public bool IsStarted { get; set; } public void Begin() { this.IsStarted = true; } } [ContractClassFor(typeof(ITestInterface))] class TestContracts : ITestInterface { ITestInterface Current { get; set; } private TestContracts() { Current = this; } #region ITestInterface Members bool ITestInterface.IsStarted { get; set; } void ITestInterface.Begin() { Contract.Requires(!Current.IsStarted); Contract.Ensures(Current.IsStarted); } Thanks in advance!

    Read the article

  • datatables-multi-filter-select

    - by user1871603
    I am using the jquery plug-in datatables. I am using the feature, datatables-multi-filter-select on my website with php code. I want to move the drop down filter from the footer to the header like in the following example: http://www.datatables.net/extras/thirdparty/ColumnFilterWidgets/DataTables/extras/ColumnFilterWidgets/ Can anyone please update the following PHP code sample to accomplish this? Code: /** * Register necessary Plugin Filters */add_filter( 'tablepress_shortcode_table_default_shortcode_atts', 'tablepress_add_shortcode_parameters_multi_filter_select' );add_filter( 'tablepress_table_render_options', 'tablepress_set_table_foot_option', 10, 2 );add_filter( 'tablepress_table_js_options', 'tablepress_add_multi_filter_select_js_options', 10, 3 );add_filter( 'tablepress_datatables_command', 'tablepress_add_multi_filter_select_js_command', 10, 5 ); /** * Add "datatables_multi_filter_select" as a valid parameter to the [table /] Shortcode */function tablepress_add_shortcode_parameters_multi_filter_select( $default_atts ) { $default_atts['datatables_multi_filter_select'] = false; return $default_atts;} /** * Make sure that "table_foot" and "datatables_scrollX" are false, if "datatables_multi_filter_select" is true, * as the footer will be appended by the JS. Scrolling will not work with automatically added content */function tablepress_set_table_foot_option( $render_options, $table ) { if ( $render_options['datatables_multi_filter_select'] ) { $render_options['table_foot'] = false; $render_options['datatables_scrollX'] = false; } return $render_options;} /** * Pass "datatables_multi_filter_select" from Shortcode parameters to JavaScript arguments */function tablepress_add_multi_filter_select_js_options( $js_options, $table_id, $render_options ) { $js_options['datatables_multi_filter_select'] = $render_options['datatables_multi_filter_select']; // register the JS if ( $js_options['datatables_multi_filter_select'] ) { $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; $js_multi_filter_select_url = plugins_url( "multi-filter-select{$suffix}.js", __FILE__ ); wp_enqueue_script( 'tablepress-multi_filter_select', $js_multi_filter_select_url, array( 'tablepress-datatables' ), '1.0', true ); } return $js_options;} /** * Evaluate "datatables_multi_filter_select" parameter and add corresponding JavaScript code, if needed */function tablepress_add_multi_filter_select_js_command( $command, $html_id, $parameters, $table_id, $js_options ) { if ( ! $js_options['datatables_multi_filter_select'] ) return $command; $name = str_replace( '-', '_', $html_id ); $datatables_name = "DT_{$name}"; $command = <<<JSvar {$name} = $('#{$html_id}'), {$datatables_name} = {$name}.dataTable({$parameters}), {$name}_tfoot, {$name}_selects, ths = '<tfoot>';{$name}.find('thead th').each( function( i ) { ths += '<th>' + datatables_fnCreateSelect( {$datatables_name}.fnGetColumnData(i) ) + '</th>';} );ths += '</tfoot>';{$name}_tfoot = {$name}.append(ths).find('tfoot');{$name}_selects = {$name}_tfoot.find('select');{$name}_tfoot.on( 'change', 'select', function() { {$datatables_name}.fnFilter( $(this).val(), {$name}_selects.index(this) );} );JS; return $command;} (function($) {/* * Function: fnGetColumnData * Purpose: Return an array of table values from a particular column. * Returns: array string: 1d data array * Inputs: object:oSettings - dataTable settings object. This is always the last argument past to the function * int:iColumn - the id of the column to extract the data from * bool:bUnique - optional - if set to false duplicated values are not filtered out * bool:bFiltered - optional - if set to false all the table data is used (not only the filtered) * bool:bIgnoreEmpty - optional - if set to false empty values are not filtered from the result array * Author: Benedikt Forchhammer <b.forchhammer /AT\ mind2.de> */$.fn.dataTableExt.oApi.fnGetColumnData = function ( oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty ) { // check that we have a column id if ( typeof iColumn == "undefined" ) return new Array(); // by default we only wany unique data if ( typeof bUnique == "undefined" ) bUnique = true; // by default we do want to only look at filtered data if ( typeof bFiltered == "undefined" ) bFiltered = true; // by default we do not wany to include empty values if ( typeof bIgnoreEmpty == "undefined" ) bIgnoreEmpty = true; // list of rows which we're going to loop through var aiRows; // use only filtered rows if (bFiltered == true) aiRows = oSettings.aiDisplay; // use all rows else aiRows = oSettings.aiDisplayMaster; // all row numbers // set up data array var asResultData = new Array(); for (var i=0,c=aiRows.length; i<c; i++) { iRow = aiRows[i]; var aData = this.fnGetData(iRow); var sValue = aData[iColumn]; // ignore empty values? if (bIgnoreEmpty == true && sValue.length == 0) continue; // ignore unique values? else if (bUnique == true && jQuery.inArray(sValue, asResultData) > -1) continue; // else push the value onto the result data array else asResultData.push(sValue); } return asResultData;}}(jQuery)); function datatables_fnCreateSelect( aData ) { var r = '<select><option value=""></option>', i, iLen = aData.length; for ( i=0 ; i<iLen ; i++ ) { r += '<option value="'+aData[i]+'">'+aData[i]+'</option>'; } return r + '</select>';}

    Read the article

  • Using Interfaces in action signature

    - by Dmitry Borovsky
    Hello, I want to use interface in Action signature. So I've tried make own ModelBinder by deriving DefaultModelBinder: public class InterfaceBinder<T> : DefaultModelBinder where T: new() { protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) { return base.CreateModel(controllerContext, bindingContext, typeof(T)); } } public interface IFoo { string Data { get; set; } } public class Foo: IFoo /*other interfaces*/ { /* a lot of */ public string Data { get; set; } } public class MegaController: Controller { public ActionResult Process( [ModelBinder(typeof(InterfaceBinder))]IFoo foo){/bla-bla-bla/} } But it doesn't work. Does anybody have idea how release this behaviour? And yes, I know that I can make my own implementation of IModelBinder, but I'm looking for easier way.

    Read the article

  • How to write a Custom DesignerSerializer for an class used by a Activity (WF)

    - by Stefan Steinegger
    I have a type which is used in a WF activity. It should be serialized. It doesn't work out of the box, most probably because of the private setters in that type. I'm not sure if this is the correct way, but I tried to write my own serializer and declared it on my class. [DesignerSerializer( typeof(FooDesignerSerializer), // my custom serializer typeof(WorkflowMarkupSerializer))] public class Foo { public Foo(int value, string name { // ... } public int Value { get; private set; } public string Name { get; private set; } } Is this the easiest way to get it serialized? How do I write this serializer? That's what I got so far: public class FooDesignerSerializer : WorkflowMarkupSerializer { protected override string SerializeToString( WorkflowMarkupSerializationManager serializationManager, object value) { // how to create a valid / XOML-like string? } }

    Read the article

  • Use the [Serializable] attribute or subclassing from MarshalByRefObject?

    - by Theo Lenndorff
    I'd like to use an object across AppDomains. For this I can use the [Serializeable] attribute: [Serializable] class MyClass { public string GetSomeString() { return "someString" } } Or subclass from MarshalByRefObject: class MyClass: MarshalByRefObject { public string GetSomeString() { return "someString" } } In both cases I can use the class like this: AppDomain appDomain = AppDomain.CreateDomain("AppDomain"); MyClass myObject = (MyClass)appDomain.CreateInstanceAndUnwrap( typeof(MyClass).Assembly.FullName, typeof(MyClass).FullName); Console.WriteLine(myObject.GetSomeString()); Why do both approaches seem to have the same effect? What is the difference in both approaches? When should I favor the one approach over the other? EDIT: At the surface I know that there are differences between both mechanisms, but if someone jumped out of a bush and asked me the question I couldn't give him a proper answer. The questions are quite open questions. I hoped that someone can explain it better than I could do.

    Read the article

  • How do I return a bit from a stored procedure with nHibernate

    - by tigermain
    I am using nHibernate in my project but I have a stored procedure which just returns a boolen of success or now. How do I code this in c#? I have tried the following but it doesnt like cause I dont have a mapping for bool!!! {"No persister for: System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"} IQuery query = NHibernateSession.CreateSQLQuery("EXEC MyDatabase.dbo.[ContentProvider_Import] :ContentProviderImportLogId", "success", typeof(bool)) .SetInt32("ContentProviderImportLogId", log.Id); var test = query.UniqueResult<bool>(); and the same result from IQuery query = NHibernateSession.CreateSQLQuery("EXEC MyDatabase.dbo.[ContentProvider_Import] :ContentProviderImportLogId") .AddEntity(typeof(bool)) .SetInt32("ContentProviderImportLogId", log.Id); var test = query.UniqueResult<bool>();

    Read the article

  • WPF DependencyProperty event before content changed

    - by morsanu
    First I will explain the context of the problem, because you might be able to point me in a better direction. I need to implement a undo-redo like system on an object. The object has a series of dependency properties. Some are double, int, string but some are also of DependencyObject type. I need to save the value of the property before it is changed, and for this I added the CoerceValueCallback. public static readonly DependencyProperty MyBackgroundProperty = DependencyProperty.Register("MyBackground", typeof(MyCustomizableBackground), typeof(MyComponent), new UIPropertyMetadata(default(MyCustomizableBackground), null, new CoerceValueCallback(OnPropertyChanged))); In OnPropertyChanged I save the value before it's changed. MyCustomizableBackground is the DependencyObject that has also some dependency properties. The problem is that in this case, where I have a custom object as a property, the OnPropertyChanged method isn't triggered, but when I have a common type, it is triggered.

    Read the article

  • Properties in Remoting

    - by Evl-ntnt
    Server: Host h = new Host(); h.Name = "JARR!!"; TcpChannel channel = new TcpChannel(8080); ChannelServices.RegisterChannel(channel); RemotingConfiguration.RegisterWellKnownServiceType(typeof(Host), "Server", WellKnownObjectMode.Singleton); Client: TcpChannel chan = new TcpChannel(); ChannelServices.RegisterChannel(chan); remoteHost = (Host)Activator.GetObject(typeof(Host), "tcp://127.0.0.1:8080/Server"); Class: [Serializable] public class Host: MarshalByRefObject { public string Name{get; set;} public Host(){} public Host(string n) { Name = n; } public override string ToString() { return Name; } } Connection OK, 8080 port opened, on client side remoteHost is not null, but remoteHost.Name == "" Why?

    Read the article

  • GetProperties() to return all properties for an interface inheritance hierarchy

    - by sduplooy
    Assuming the following hypothetical inheritance hierarchy: public interface IA { int ID { get; set; } } public interface IB : IA { string Name { get; set; } } Using reflection and making the following call: typeof(IB).GetProperties(BindingFlags.Public | BindingFlags.Instance) will only yield the properties of interface IB, which is "Name". If we were to do a similar test on the following code, public abstract class A { public int ID { get; set; } } public class B : A { public string Name { get; set; } } the call typeof(B).GetProperties(BindingFlags.Public | BindingFlags.Instance) will return an array of PropertyInfo objects for "ID" and "Name". Is there an easy way to find all the properties in the inheritance hierarchy for interfaces as in the first example?

    Read the article

  • Add custom Model Binders for derived objects and their base

    - by mare
    My class diagram: BaseContentClass Page inherits BaseContentClass Tab inherits BaseContentClass ... If I do this ModelBinders.Binders.Add(typeof(BaseContentObject), new BaseContentObjectCommonPropertiesBinder()); then when in controller action parameter of type Tab appears, custom model binder is not fired. It gets fired if I do this: ModelBinders.Binders.Add(typeof(Tab), new BaseContentObjectCommonPropertiesBinder()); But I don't want to go writing "n" number of Add statements in my global.asax.cs to associate all the derived classes with my custom model binder, do I? I don't know if I have any other option.

    Read the article

  • How can I check if a particular jQuery UI function is available and use a different function if it i

    - by Mark B
    I'm writing a jQuery plugin and I would like my code to take advantage of the jQuery UI show(effect, [options], [speed], [callback]) and hide(effect, [options], [speed], [callback]) functions, which allow you to show and hide elements with a nice animation. However, I'd also like my plugin to degrade gracefully if jQuery UI isn't available, switching back to use the basic, non-animating show() and hide() functions present in the standard jQuery API. I'll need to test for the show and hide functions specifically, as even if jQuery UI is available it could potentially be a custom version, without the Effects components included. At first I thought that I might be able to do something like: if(typeof myelement.show('blind', 'slow') == 'undefined') { myelement.show('blind', 'slow'); } else { myelement.show(); } But of course this doesn't work, as even if UI isn't present, show() is still a function, it just has a different signature—so typeof returns object in either case. So, what's the best way for me to check if jQuery UI is available to my plugin? Any help is much appreciated!

    Read the article

  • Bound DataGridView not updating data source

    - by Max Yaffe
    I'm trying to bind a table of structures to a DataGridView. Loading and viewing the table is working fine but I can't edit a value and get it stored back into the table. Here's what I'm doing. I have a "primitive" data type, Real defined by public struct MyReal:IMyPrimative { public Double m_Real; //... public MyReal(String val) { m_Real = default(Double); Init(val); } //... } It gets used in a structure: public struct MyReal_Record : IMyRecord { public MyReal Freq { get; set;} MyReal_Record(String[] vals) { Init(vals); } } And the structure is used to define a table using a generic Binding List public class MyTable<S> : BindingList<S> where S: struct, IMyRecord { public Type typeofS; public MyTable() { typeofS = typeof(S); // ... } This table is used as a binding source for a grid, dynamically. private void miLoadFile_Click(object sender, EventArgs e) { MyModel.Table<Real_Record> RTable = new MyModel.Table<Real_Record>(); //... Table initialized here //set up grid with virtual mode dataGridView1.DataSource = RTable; } All of this works fine and I can create RTable, initialize it and display it in a grid. The grid allows editing and has events set for CellParsing and CellFormatting which look like: private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.DesiredType != typeof(String)) return; e.Value = e.Value.ToString(); } private void dataGridView1_CellParsing(object sender, DataGridViewCellParsingEventArgs e) { if (e.DesiredType != typeof(MyReal)) return; e.Value = new MyReal(e.Value.ToString()); e.ParsingApplied = true; this.dataGridView1.UpdateCellValue(e.ColumnIndex, e.RowIndex); } When I edit a value in a cell, I can change the text. On leaving the cell, CellParsing fires and the event handler is called. Everything seems to be correct going into the CellParsing handler. e.DesiredType is MyReal. e.Value is a string with the new value. After the new MyReal is created from the string, e.Value is set correctly. RowIndex and ColumnIndex are correct. ReadOnly is set false. However, when I leave the cell, the system restores the original value to the cell. I thought the UpdateCellValue would replace the value in the dataSource but I seem to be missing something. What did I miss? Thanks, Max

    Read the article

  • MS Test : How do I enforce exception message with ExpectedException attribute

    - by CRice
    I thought these two tests should behave identically, in fact I have written the test in my project using MS Test only to find out now that it does not respect the expected message in the same way that nunit does. nunit (fails): [Test, ExpectedException(typeof(System.FormatException), ExpectedMessage = "blah")] public void Validate() { int.Parse("dfd"); } ms test (passes): [TestMethod, ExpectedException(typeof(System.FormatException), "blah")] public void Validate() { int.Parse("dfd"); } No matter what message I give the ms test, it will pass. Is there any way to get the ms test to fail if the message is not right? Can I even create my own exception attribute? I would rather not have to write a try catch block for every test where this occurs.

    Read the article

  • AesCryptoServiceProvider not part of SymmetricAlgorithm?

    - by user330006
    I have a quick little app that steps through the possible symmetric encryption methods. I get them with the following line: private static List<Type> GetAlgorithmTypes { get { return Assembly.GetAssembly(typeof(SymmetricAlgorithm)).GetTypes().Where( type => type.IsSubclassOf(typeof(SymmetricAlgorithm))).ToList(); } } As you can see when i run this, AesCryptoServiceProvider is not a member of this group, even though it inherits from AES, which does belong to SymmetricAlgorithm and shows up in my list. This wouldn't be so much of a problem, i can manually add the provider in the group if i have too, but then if i try to retrieve this type by its name: Type t = Type.GetType("System.Security.Cryptography.AesCryptoServiceProvider"); i get a null object for AesCryptoServiceProvider, but not for any of the other items in the group. This is really strange, and i'm wondering if anyone has any ideas. It's kinda making me need to use tripleDES because of this (since my machines are all running the FIPS compliance requirement). Thanks for any help!

    Read the article

  • C# simpler run time generics

    - by Hellfrost
    Is there a way to invoke a generic function with a type known only at run time? I'm trying to do something like: static void bar() { object b = 6; string c = foo<typeof(b)>(); } static string foo<T>() { return typeof (T).Name; } Basically I want to decide on the type parameter only at run time, but the function I'm calling depends on the type parameter. Also I know this can be done with reflections... but it's not the nicest solution to the problem... I'm sort of looking for dynamic features in C#...

    Read the article

  • union marshalling issue in C#

    - by senthil
    I have union inside structure and the structure looks like struct tDeviceProperty { DWORD Tag; DWORD Size; union _DP value; }; typedef union _DP { short int i; LONG l; ULONG ul; float flt; double dbl; BOOL b; double at; FILETIME ft; LPSTR lpszA; LPWSTR lpszW; LARGE_INTEGER li; struct tBinary bin; BYTE reserved[40]; } __UDP; struct tBinary { ULONG size; BYTE * bin; }; from the tBinary structure bin has to be converted to tImage (structure is given below) struct tImage { DWORD x; DWORD y; DWORD z; DWORD Resolution; DWORD type; DWORD ID; diccid_t SourceID; const void *buffer; const char *Info; const char *UserImageID; }; to use the same in c# I have done marshaling but not giving proper values when converting the pointer to structure. The C# code is follows, tBinary tBin = new tBinary(); IntPtr tBinbuffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(tBin)); Marshal.StructureToPtr(tBin.bin, tBinbuffer, false); tDeviceProperty tDevice = new tDeviceProperty(); tDevice.bin = tBinbuffer; IntPtr tDevicebuffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(tDevice)); Marshal.StructureToPtr(tDevice.bin, tDevicebuffer, false); Battary tbatt = new Battary(); tbatt.value = tDevicebuffer; IntPtr tbattbuffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(tbatt)); Marshal.StructureToPtr(tbatt.value, tbattbuffer, false); result = GetDeviceProperty(ref tbattbuffer); Battary v = (Battary)Marshal.PtrToStructure(tbattbuffer, typeof(Battary)); tDeviceProperty v2 = (tDeviceProperty)Marshal.PtrToStructure(tDevicebuffer, typeof(tDeviceProperty)); tBinary v3 = (tBinary)Marshal.PtrToStructure(tBinbuffer, typeof(tBinary));

    Read the article

< Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >