Click here to Skip to main content
15,867,453 members
Everything / Marshalling

Marshalling

marshalling

Great Reads

by Dan Randolph
C# interop using platform invoke and C++ vectors to implement fast searching and selection on index keys

Latest Articles

by Dan Randolph
C# interop using platform invoke and C++ vectors to implement fast searching and selection on index keys

All Articles

Sort by Score

Marshalling 

3 Dec 2019 by Richard Deeming
Marshal.PtrToStructure Method (System.Runtime.InteropServices) | Microsoft Docs[^]: structure: The object to which the data is to be copied. This must be an instance of a formatted class. You've created a new array of MyPoint, but you haven't initialized it. Therefore, every slot within the...
22 Feb 2013 by Bernhard Hiller
Run your service with your credentials - otherwise it won't be able to access Word running with your credentials.
17 Feb 2014 by Pete O'Hanlon
Marhalling tends to be the term used to describe the process of transforming data so that it can either be stored (i.e., marshalling data), or moved. So, when you hear about an event being marshalled, what this means (in effect) is transforming the event so that it can be moved over threads - in...
17 Feb 2014 by mehdijafary
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file, a memory buffer, or transmitted across a network connection to be used later in the same or another computer environment. And this sequence of bits can be of any...
16 Oct 2015 by bling
Don't kill yourself trying to become an expert at data marshaling when you don't need to be one.Create a new VB.NET assembly (say "Types") and put all your data structures there.Add a reference to this assembly in both the native and existing VB.NET projects.Enable managed eg....
18 Sep 2016 by Richard MacCutchan
See InetAddress (Java Platform SE 7 )[^].
9 Jul 2018 by AlwaysLearningNewStuff
INTRODUCTION I am buidling in-proc COM server to be consumed by VB6 client. COM server needs to use blocking function[^]. This means that the VB6 GUI would be blocked until function retrieves the result, which is unacceptable. Therefore I will use the function in a worker thread, and notify...
6 Jul 2018 by KarstenK
You are NOT only marshalling the interface, but the object and all related obejcts and their memory. That wont work!!! You need to create the instance of the object in the worker thread and do the work. Best is to provide some output memory for the results which the worker thread must write. ...
8 Jul 2013 by _Asif_
Quickest solution is to put this dll in WINDOWS\SYSTEM32 folder and see whether it gets loaded or not.
5 Aug 2013 by MarjKK
Reading up on marshaling, I thought the following would be valid but the marshaling fails. The C++ definition is as follows:typedef struct{ char* t; size_t t_length; double d;} A;typedef struct{ char* t; size_t t_length; char* k; size_t...
5 Aug 2013 by Sergey Alexandrovich Kryukov
C++ unions can be matched in .NET by the layouts created using [FieldOffset] member attribute, System.Runtime.InteropServices.FieldOffsetAttribute. Please see:http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.fieldoffsetattribute.aspx[^].The code sample in the MDSN...
6 Oct 2013 by staretzu
Hi guys,I'm preparing to work on a project and need some 'best practice' advise. In this project I have to read/write from/to a USB Device at predefined intervals, and I have to share results on both web and desktop applications. Besides this I need to save logs to database. I need to...
3 Dec 2013 by Dave Kreskowiak
This is where you have to contact the manufacturer of your device and the SDK. It's extremely unlikely anyone here is going to have any experience with the exact device you're using.
8 Dec 2013 by Luiey Ichigo
Found it..when calling DLL import on RunAccept, I put the declaration as ByRef. I search and found someone advise to change to ByVal. And it's work..
14 Dec 2013 by Member 4479742
Hi i stored class object in logical data(call context) ,when i try to access the logical data(call context) from different app domain,I'm getting system.runtime.serialization issue. Following my code will reproduce my issue . public static class Program { private...
13 May 2014 by theskiguy
I have a VB.net app that I use to communicate with a Fanuc CNC controller with a PC front end using the Fanuc Focas Libraries. The Fanuc CNC controller controls the operation of a machine tool that is used to cut metal parts. The Focas libraries has a series of different functions I can call to...
13 May 2014 by Alan N
Why not just replace the variable size structure ODBAXIS with an integer array allocated at run time with a length one element longer than the expected amount of data, i.e. 9 or 33. The dummy and type fields would now be in element(0) and could be extracted out if actually needed. The data...
3 Dec 2014 by theafien
I Have this struct:public struct A{ public int first;}public struct B{ [MarshalAs(UnmanagedType.ByValArray, SizeConst=32)] public char[] first;}[StructLayout(LayoutKind.Explicit)]public struct CUnion{ [FieldOffset(0)] public A _a; ...
3 Dec 2014 by Er. Dinesh Sharma
Please Try thispublic struct A { public int first; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct B { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public char[] first; } [StructLayout(LayoutKind.Explicit)] ...
27 Apr 2015 by shankha2010
Hi All I am new to C# and marshalling.My objective is:Creating an Interface in C# and implementing it in class.One of method will take a structure [if not a good idea then pointer to structure]For now I an try filling the structure with primitive datatype.Generating a dll and tlb out...
25 Apr 2015 by KarstenK
If you are working with primitive data type you can use direct memory access via casting. It is better to create memory in the process/language where you used it and NOT transfer between c# and C++. If you want to use C# objects in C++ you need CLR project in C++.Take a look at my article...
27 Apr 2015 by shankha2010
Hi All thanks for the response , Actually I have to use non CLR C++ native code.I got the answer from :Heresee the Native Exe calling Managed DllJust twisted little bit for my needC# code:using System;using System.Collections.Generic;using System.Text;using...
11 May 2015 by sreedharmaruthi
Hi, I have structure :struct StartReadXML { public int CmdID;//3 public char[] CmdName;//ReadXML public char[] Description; };With initializations as below :StartReadXML startXML=new StartReadXML(); startXML.CmdID = 3; ...
3 Jun 2015 by Member 10772496
Hello world,In my VB.net code I call a C++ dll, which should return a ouput structure.I have a problem when the vb.net code read this structure !The c++ structure is :struct output_data{ SAFEARRAY *output1; SAFEARRAY *output2;}In the VB.net side i declare the...
5 Jun 2015 by Richard MacCutchan
You already posted this question at Calling a C++ DLL function from VB.NET having SAFEARRAY structure[^]. If you have further information then please edit the original, as that already contains some suggestions. Please do not repost.
14 Oct 2015 by Member 10772496
Hi,I have a problem to pass a structure contained a structure pointer from VB.net to a C++ dll.When i try the following code, this exception is raised :'System.Runtime.InteropServices.COMExceptionIn VB.net side i do :Private Declare Function Cpp_NOR Lib "XLSTATLINK.dll"...
6 Nov 2015 by KarstenK
If you only what to set a callback function it is fairly easy, as described in my article.A more complex scenario with classes is in the article How to Marshal a C++ Class displayed.
18 Sep 2016 by Tejas Sawant 13
I have put lot of efforts, googled and tried all possible ways. But I did not got satisfaction so I come here finally.I want to convert below line of code [C#] into java. 1] Method used to convert IP into uintprivate uint GetIP(string strIp) { System.Net.IPAddress...
28 Nov 2016 by Member 11254844
//Define Code internal static class UnsafeMethods { [DllImport("kernel32.dll", SetLastError = true)] internal extern static IntPtr LoadLibrary(string libraryName); [DllImport("kernel32.dll", SetLastError = true)] internal extern static bool FreeLibrary(IntPtr hModule);...
11 Mar 2017 by JBHowl
I have two byte[] that represent bitmaps. I want to copy them in to one bitmap, placing them next to each other. Is this possible with marshal? See the code below for how i'd like it to work. Thanks in advance.//Bitmap 100x100 byte[] frame1 = null; //Bitmap...
11 Mar 2017 by RickZeeland
It is not necessary to use Marshal, you can use something like this: graphics.DrawImage ( bitmap, new Rectangle ( 0, 0, Width, Height ), new Rectangle ( 0, 0, Width, Height ), GraphicsUnit.Pixel );As this might be too slow for you, maybe this will be more to your liking: Fast...
11 Mar 2017 by Midi_Mick
Probably the easiest fast solution for putting the images next to each other would be to use the Bitmap.BitBlt Method[^]. This means that you would have to convert the byte[] arrays to bitmaps first, but using the LockBits method as you do above should make that simple enough. Trying to put the...
18 Jul 2018 by Member 10020245
I have a SDK from a third party -- A camera vendor (Hasselblad) that has provided an SDK for interfacing a PC to his camera. The SDK consists of a C++ DLL and an unmanaged C++ sample application that uses the DLL. I am able to get all the methods properly marshalled into my C# code except the...
10 Sep 2018 by bernova
[DllImport("DK_V2.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] //C++ int GetUs(void* con, uint32_t devId, char** ubjs, uint32_t* nid); I convert above function to c# code as follow : extern public static int GetUs(IntPtr con,out int...
10 Sep 2018 by Matias Lopez
Check this CodeProject post! Marshalling with C#
3 Dec 2019 by Praveen Kumar Katiyar
I have a following code in a C++ DLL typedef struct _MYPOINT { int nX; int nY; } MYPOINT; extern "C" __declspec(dllexport) void ModifyPointArray (int nSize, MYPOINT *ptArr[]) { for ( int nI = 0; nI nX +=5; ptArr[nI]->nY +=5; } } ...
9 Mar 2021 by Amir Hamza Kayes
I have a first method of a C++ dll 1.HRESULT WINAPI StartInit(Void) 2.HREULT WINAPI LoadInitBitmap(LPWSTR IpBMPFilename, UINT uid); How can I load the dll and define those methods. What I have tried: [DllImport("tjp.dll", EntryPoint =...
9 Mar 2021 by Richard MacCutchan
The DllImport declaration must define the actual entry point that you wish to call [DllImport("tjp.dll", EntryPoint = "StartInit")] // static extern IntPtr StartInit(); public Form1() { InitializeComponent(); } private void...
10 Mar 2021 by OriginalGriff
It's a generic error which basically says "that's a bad pointer you are playing with there". Since we have no idea what "tjp.dll" contains, let alone what parameters it's methods expect, we really can't help that much. It's almost certainly the...
18 Aug 2012 by Dan Randolph
C# interop using platform invoke and C++ vectors to implement fast searching and selection on index keys
17 Feb 2014 by Sander Rossel
Hi all,I have a question about marshalling.The wikipedia page about marshlling (and other pages and articles across the web) describe marshalling as being similiar to serialization, transforming an object into a format that is suited for transporting data to other processes.That is...
11 May 2015 by _Asif_
Check this out. How to convert a structure to a byte array in C#?[^]
13 May 2014 by Sergey Alexandrovich Kryukov
Of course there are better options. Moreover, deploying two applications instead of one would be a complete lame and the end of the maintainability of you product (if you even had it so far). Functionally, they are the same. Do you remember one of the most important principle in programming?...
5 Nov 2015 by shankha2010
I want to callback C# method from "C++ COM dll", Here is the strategy I took.Step 1:In C++ Server.dll in idl I declared 2 class Class1 and Class2 as below. [ object, uuid(54120D45-09DE-4e61-AA30-858CE4C472B5), oleautomation, helpstring("Class1...
8 Jul 2013 by Katiyar S.
Hello Experts,I have created a Native Dll (myNativeDll.dll) just to keep it simple it exposes one method.__declspec(dllexport)char * GetStringFromDll( ){ const size_t alloc_size = 128; STRSAFE_LPSTR result = (STRSAFE_LPSTR)CoTaskMemAlloc( alloc_size ); STRSAFE_LPCSTR...
11 May 2015 by sreedharmaruthi
Thanks for your help :)!This one worked for me[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]as below: struct StartReadXML { public int CmdID;//3 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)] public string CmdName;//ReadXML...
18 Apr 2018 by Member 13769719
Add reference only of "Microsoft.Office.Interop.Excel.dll" try { //This requires excel app (excel.exe*32) to be running means any excel sheet should be open. If excel not running then it will throw error. excelApp =...
18 Apr 2018 by muneebalikiyani
I am trying to access Microsoft word instance through my service but I am getting this errorOperation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE)) , I have opened word document ( i can also see WINWORD.EXE in Task Manager) , I am using VS 2010 and MS Office 2003....
3 Dec 2013 by Luiey Ichigo
Hi all,I create a program to operate a device. The device is check acceptor. When the device is ready accepting, I place the check and the device will feed. But the exception raise after check is feeding "Attempt to read or write Protected Memory. This is often an indicating that other...