marshalling

Correct way to marshal SIZE_T* ?

I have the following C++ function definition, which I am trying to call through PInvoke from managed code: bool FooBar(SIZE_T* arg1); My managed declaration looked as follows: [DllImport("mydll", SetLastError=true, CharSet=CharSet.Unicode)] private static extern bool FooBar(ref uint arg1); Some of you may notice the same bug I even...

IntPtr arithmetics

I tried to allocate an array of structs in this way: struct T { int a; int b; } data = Marshal.AllocHGlobal(count*Marshal.SizeOf(typeof(T)); ... I'd like to access to allocated data "binding" a struct to each element in array allocated with AllocHGlobal... something like this T v; v = (T)Marshal.PtrToStructure(data+1, typeof(T))...

Marshaling pointer to an array of strings

I am having some trouble marshaling a pointer to an array of strings. It looks harmless like this: typedef struct { char* listOfStrings[100]; } UnmanagedStruct; This is actually embedded inside another structure like this: typedef struct { UnmanagedStruct umgdStruct; } Outerstruct; Unmanaged code calls back into managed co...

Marshal.SizeOf error in computing size.

i have a structure public struct SERVER_USB_DEVICE { USB_HWID usbHWID; byte status; bool bExcludeDevice; bool bSharedManually; ulong ulDeviceId; ulong ulClientAddr; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] string usbDe...

Can you use .net 3.5 Action or Func as Marshalled unmanaged delegates?

After reading Dynamically calling unmanaged dlls in .net I've been trying to modify the code to my liking. I made a class that implements idisposable to wrap load calls in and free them when needed. However I can't seem to figure out the syntax if it is possible to use anonymous delegates with it. var loaded=DynamicLibraryLoader.TryLo...

Marshaling a Byte array to a C# structure.

Hello, I'm working on a C# project for reading FAT32 Boot Sector and BPB, The problem is that I'm using a marshaling mechanism to convert a byte array to a Custom FAT32 data structure. I get a message error saying : Could not load type 'FAT32Management.Fat32BootSector' from assembly 'FAT32Management, Version=1.0.0.0, Culture=neutral, Pub...

Marshaling javascript dictionaries to Silverlight

I have had not trouble passing primitive values from Javascript to Silverlight through the HTML bridge, but I keep getting stuck when trying to pass a Dictionary. Furthermore, I can't find a single sample of this working anywhere online, though the MSDN documentation says it should just happen automatically. Instead, I get an error tha...

Pass a Delphi set to an external Delphi function from C#

I'm trying to call an external Delphi function from C# which takes a Delphi set as a parameter: Delphi code type tStatus = (sIn, sOut, sAbsent, sSick); tStatusSet = set of tStatus; function LoadEmployees(tStatusSet aStatusSet): tEmpList; I need to marshall a C# array of enum values (that is elements from tStatus) into a format t...

Managing C++ Garmin API in C#

I want to call Garmin API (http://developer.garmin.com/mobile/mobile-sdk/) in VB.Net Compact Framework project. The API is in C++, so i´m making a C# dll project as intermediate way between API dll and VB.Net. I have some problems while executing my code because it throw a NotSupportedException (bad arguments type, i think) in QueCreateP...

COM interface declarations

Hi, When creating COM interface declarations in C# are there any "rules" you have to stick to? I think there are and would like to get some info on it. For example I'm toying around with the ITaskbarList, ITaskbarList2 and ITaskbarList3 interfaces and it seems to me that I Have to declare the order of the members in the manages implem...

Calling .NET assembly using Xslt from Delphi 5 Win32 assembly.

This is my first attempt to call a .NET assembly from a Delphi 5 (Win32) native assembly. I am only familiar with C# and .NET so please bear with me. I guess I will walk thru this layer by layer. Here is the code for the C# assembly I am attempting to execute from the Delphi 5 assembly. using System; using System.Collections.Generic; us...

C# Newbie: How do I fix this code to do a DNS lookup?

This is my first time using C#, so I'm very much out of my element. But I have faith that the wonderful people here at Stack Overflow can help me out! I've come up with the following code (below) based on some other pieces of code I found floating around on the internet. What I am trying to do is to look up all the "text" DNS records (TX...

equivalent char* in C#

Hello, I have a dll that is written in c++. And I am p/invoking to call the functions. I have this c++ declaration. int dll_registerAccount(char* username, char* password); I have done this dllimport declaration: [DllImport("pjsipDlld")] static extern int dll_registerAccount(IntPtr username, IntPtr password); Would my DllImport b...

C#: marshalling a struct that contains arrays

I am doing some C# interop work. I have the following struct: #pragma pack(push,1) typedef struct { unsigned __int64 Handle; LinkType_t Type; LinkState_t State; unsigned __int64 Settings; signed __int8 Name[MAX_LINK_NAME]; unsigned __int8 DeviceInfo[MAX_LINK_DEVINFO]; unsigned __int8 Reserved[40]; } LinkInfo_...

Generic BitConverter-like method?

Hello, I've recently encountered a situation where I need to create a generic method to read a datatype out of a byte array. I've created the following class: public class DataStream { public int Offset { get; set; } public byte[] Data { get; set; } public T Read<T>() where T : struct { unsafe { ...

interfacing erlang application with php

Hi, I have a website built with PHP. I have an Erlang application running as a daemon on the same server. I need to call functions on the Erlang application from PHP and get back the result. I've found PHP/Erlang and over PHP modules but I can't install a PHP module on this server, I can only use PHP code. The only way I know to solve...

What is wrong with my DLLImport of LogonUser with String Marshaling? [C#]

For some odd reason, when I marshal the LogonUser DLLImport parameters I am no longer able to login succesfully when using the INTERACTIVE logon type, it works for NETWORK logon type. This is my code: [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool LogonUser ( ...

JAXB - Add a node to the XML as html link

I have a basic JavaBean in my service layer and originally it was not designed for marshalling. This object is used by both JAX-WS, JAX-RS, and Servlets in other layers of my application. I want to take advantage of a drill down type effect in my REST services so my question is: How do I make one of the fields/properties of the javabe...

Marshalling array of strings to char ** in C#. Must be quite easy (if you know how ;-)

Hi, I'm calling a C DLL function and need to supply the following C struct: typedef struct { char *mTableId; char **mFieldNames; int mNumFields; char *mFilter; char *mSort; int mOffset; int mMaxRecords; char *mTargetRecordFilter; int mSurroundingRec...

Wrong timezone being used in Java web service

I have a JAX-B java web service which I'm using to update a database. Each row in the table that I'm updating is represented by an object similar to below: - public class Item { private String id; private Date startDate; private Date endDate; public Item() { } ... } This class is being instantiated in a separate...