标签: marshalling

当前上下文中不存在"Marshal"这个名称

我从bitmapmixer示例(DirectShow.NET)获得了下面的代码,我试图重新实现它.原始样本工作正常.在我的版本中,当我尝试编译时,我得到错误.

private void AddHandlers()
    {
        // Add handlers for VMR purpose
        this.Paint += new PaintEventHandler(Form1_Paint); // for WM_PAINT
        this.Resize += new EventHandler(Form1_ResizeMove); // for WM_SIZE
        this.Move += new EventHandler(Form1_ResizeMove); // for WM_MOVE
        SystemEvents.DisplaySettingsChanged += new EventHandler(SystemEvents_DisplaySettingsChanged); // for WM_DISPLAYCHANGE
        handlersAdded = true;
    }

    private void RemoveHandlers()
    {
        // remove handlers when they are no more needed
        handlersAdded = false;
        this.Paint -= new PaintEventHandler(Form1_Paint);
        this.Resize -= new EventHandler(Form1_ResizeMove);
        this.Move -= new EventHandler(Form1_ResizeMove);
        SystemEvents.DisplaySettingsChanged -= new EventHandler(SystemEvents_DisplaySettingsChanged);
    }
Run Code Online (Sandbox Code Playgroud)

错误


错误1当前上下文中不存在名称"Marshal"Form1.cs
错误2 当前上下文中不存在名称"Marshal"Form1.cs …

marshalling directshow.net c#-3.0

1
推荐指数
1
解决办法
5526
查看次数

Grails JSON marshaller中的自定义字符串格式

我正在寻找一种通过Grails JSON转换进行字符串格式化的方法,类似于我在本文中找到的自定义格式化日期.

像这样的东西:

import grails.converters.JSON;

class BootStrap {

     def init = { servletContext ->
         JSON.registerObjectMarshaller(String) {
            return it?.trim()             }
     }
     def destroy = {
     }
}
Run Code Online (Sandbox Code Playgroud)

我知道自定义格式可以在每个域类的基础上完成,但我正在寻找更全面的解决方案.

grails groovy json marshalling converters

1
推荐指数
1
解决办法
3465
查看次数

如何在C#中编组一个IntPtr的异常

我想Exception在非托管C程序集中保留指向托管对象的指针.

我尝试了很多方法.这是我发现的唯一通过我的初步测试的人.

有没有更好的办法?

我真正想做的是处理ExceptionWrapper构造函数和析构函数中的alloc和free方法,但是struct不能有构造函数或析构函数.

编辑:回复:为什么我想这样:

我的C结构有一个函数指针,该指针由一个托管委托作为非托管函数指针封送.受管代理使用外部设备执行一些复杂的测量,在这些测量期间可能会出现异常.我想跟踪发生的最后一个及其堆栈跟踪.现在,我只保存异常消息.

我应该指出托管委托不知道它与C DLL交互.

public class MyClass {
    private IntPtr _LastErrorPtr;

    private struct ExceptionWrapper
    {
        public Exception Exception { get; set; }
    }

    public Exception LastError
    {
        get
        {
            if (_LastErrorPtr == IntPtr.Zero) return null;
            var wrapper = (ExceptionWrapper)Marshal.PtrToStructure(_LastErrorPtr, typeof(ExceptionWrapper));
            return wrapper.Exception;
        }
        set
        {
            if (_LastErrorPtr == IntPtr.Zero)
            {
                _LastErrorPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ExceptionWrapper)));
                if (_LastErrorPtr == IntPtr.Zero) throw new Exception();
            }

            var wrapper = new ExceptionWrapper();
            wrapper.Exception = value;
            Marshal.StructureToPtr(wrapper, _LastErrorPtr, true); …
Run Code Online (Sandbox Code Playgroud)

.net c c# clr marshalling

1
推荐指数
1
解决办法
1131
查看次数

创建名为'org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter'的bean时出错

我正在尝试一个简单的弹簧Web服务应用程序.我已正确配置应用程序,但当我尝试访问wsdl文件时,我收到以下错误:

    at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_07]

17:24:35,409 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/springWsTest]] (http--127.0.0.1-8080-1) Initializing Spring FrameworkServlet 'webservice'
17:24:35,419 INFO  [org.springframework.ws.transport.http.MessageDispatcherServlet] (http--127.0.0.1-8080-1) FrameworkServlet 'webservice': initialization started
17:24:35,428 INFO  [org.springframework.web.context.support.XmlWebApplicationContext] (http--127.0.0.1-8080-1) Refreshing WebApplicationContext for namespace 'webservice-servlet': startup date [Tue Jul 03 17:24:35 BST 2012]; parent: Root WebApplicationContext
17:24:35,443 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (http--127.0.0.1-8080-1) Loading XML bean definitions from ServletContext resource [/WEB-INF/ws-config.xml]
17:24:35,541 INFO  [org.springframework.context.annotation.ClassPathBeanDefinitionScanner] (http--127.0.0.1-8080-1) JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
17:24:35,595 INFO  [org.springframework.context.annotation.ClassPathBeanDefinitionScanner] (http--127.0.0.1-8080-1) JSR-330 'javax.inject.Named' annotation found and supported for component scanning
17:24:35,655 INFO  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] …
Run Code Online (Sandbox Code Playgroud)

java spring web-services jaxb marshalling

1
推荐指数
1
解决办法
1万
查看次数

如何从编组指针读取uint?

我有一个本机方法,需要一个指针来写出一个dword(uint).

现在我需要从(Int)指针获取实际的uint值,但Marshal类只有读取(签名)整数的方便方法.

如何从指针获取uint值?

我搜索了问题(和谷歌),但找不到我需要的东西.

示例(不工作)代码:

IntPtr pdwSetting = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(uint)));

        try
        {
            // I'm trying to read the screen contrast here
            NativeMethods.JidaVgaGetContrast(_handleJida, pdwSetting);
            // this is not what I want, but close
            var contrast = Marshal.ReadInt32(pdwSetting);
        }
        finally
        {
            Marshal.FreeHGlobal(pdwSetting);
        }
Run Code Online (Sandbox Code Playgroud)

来自本机函数的返回值是0到255之间的双字,其中255是完全对比.

c# pinvoke marshalling

1
推荐指数
2
解决办法
5136
查看次数

元帅浮动*到C#

我有一个DLL导出一个返回float*的函数,我想在我的C#代码中使用它.我不知道如何制作我的浮动*以便我可以安全地在C#中使用它.所以,在我的C++ DLL中,我声明了:

static float* GetSamples(int identifier, int dataSize);
Run Code Online (Sandbox Code Playgroud)

在我的C#脚本中,我有:

[DllImport ("__Internal")]
public static extern float[] GetSamples (int identifier, int dataSize);
Run Code Online (Sandbox Code Playgroud)

C++ GetSamples(int,int)分配内存并返回float数组的指针.如何将C#GetSamples声明为Marshal我的float数组,以及如何访问数据(通过迭代或Marshal.Copy)?另外,我可以从C#中删除float*还是必须调用另一个C++函数来删除分配的内存?

编辑:所以这是我现在尝试过的.首先,在C#方面:

宣言:

[DllImport ("__Internal")]
public static extern int GetSamples ([In, Out]IntPtr buffer,int length, [Out] out IntPtr written);
Run Code Online (Sandbox Code Playgroud)

试着打电话给它:

IntPtr dataPointer = new IntPtr();
IntPtr outPtr;
GetSamples(dataPointer, data.Length, out outPtr);
for (var i = 0; i < data.Length; i++){
    copiedData[i] = Marshal.ReadByte(dataPointer, i);
}
Run Code Online (Sandbox Code Playgroud)

然后在我的C++ lib中:

int AudioReader::RetrieveSamples(float * sampleBuffer, size_t dataLength, size_t * /* out */ written)
{ …
Run Code Online (Sandbox Code Playgroud)

c# c++ dll memory-management marshalling

1
推荐指数
1
解决办法
5300
查看次数

如何在jaxb编组期间跳过空字段

marshaller是否有办法生成一个跳过任何null属性的新xml文件?因此someAttribute =""之类的内容不会出现在文件中.

谢谢

null attributes jaxb marshalling

1
推荐指数
1
解决办法
9610
查看次数

JAXB,Marshal的问题, - 无法编组类型"java.lang.String"

我遇到了问题,我使用带有xjc的架构xsd生成了类.当我运行marshal操作时,我收到以下错误:

[com.sun.istack.internal.SAXException2: unable to marshal type "java.lang.String" as an element because it is missing an @XmlRootElement annotation]    at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(Unknown Source)    at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(Unknown Source)  at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(Unknown Source)    at prova.StampGenericXML.staticStampGenericXML(StampGenericXML.java:42)     at prova.TestLauncher.main(TestLauncher.java:199) Caused by: com.sun.istack.internal.SAXException2: unable to marshal type "java.lang.String" as an element because it is missing an @XmlRootElement annotation     at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(Unknown Source)   at com.sun.xml.internal.bind.v2.runtime.LeafBeanInfoImpl.serializeRoot(Unknown Source)  at com.sun.xml.internal.bind.v2.runtime.property.SingleReferenceNodeProperty.serializeBody(Unknown Source)  at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(Unknown Source)     at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(Unknown Source)    at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(Unknown Source)    at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(Unknown Source)     at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(Unknown Source)    at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(Unknown Source)    at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(Unknown Source)     at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(Unknown …
Run Code Online (Sandbox Code Playgroud)

java string jaxb marshalling

1
推荐指数
1
解决办法
9340
查看次数

在32位中编组结构时的行为与64位运行时中的行为不同

我在PInvoking SetupDiCreateDeviceInfoList时发现了这个.

C++函数签名是:

HDEVINFO SetupDiCreateDeviceInfoList(
  _In_opt_ const GUID *ClassGuid,
  _In_opt_       HWND hwndParent
);
Run Code Online (Sandbox Code Playgroud)

在C#中我定义了GUID这样的结构:

[StructLayout(LayoutKind.Sequential)]
public struct GUID
{
    public uint Data1;
    public ushort Data2;
    public ushort Data3;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
    public byte[] Data4;
}
Run Code Online (Sandbox Code Playgroud)

和这样的功能:

[DllImport("Setupapi.dll")]
public static extern IntPtr SetupDiCreateDeviceInfoList(GUID ClassGuid, IntPtr hwndParent);
Run Code Online (Sandbox Code Playgroud)

由于在C#结构中默认情况下通过副本传递(与类不同),因此该函数签名不应匹配.确实在32位运行时调用该函数时:

GUID classGuid = new GUID();
IntPtr deviceInfoSet = SetupDiCreateDeviceInfoList(classGuid, IntPtr.Zero);
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

SetupDiCreateDeviceInfoList'使堆栈失衡.这很可能是因为托管PInvoke签名与非托管目标签名不匹配.检查PInvoke签名的调用约定和参数是否与目标非托管签名匹配.

但是在64位运行时,上面的代码可以工作.为什么???

当然,如果我通过引用传递结构,则该函数在32位和64位运行时都能正常工作:

[DllImport("Setupapi.dll")]
public static extern IntPtr SetupDiCreateDeviceInfoList(ref GUID ClassGuid, IntPtr hwndParent);

GUID classGuid = new GUID();
IntPtr …
Run Code Online (Sandbox Code Playgroud)

c# pinvoke winapi marshalling data-structures

1
推荐指数
1
解决办法
447
查看次数

MarshalJSON错误,顶级后无效字符"g"

我为我的ID制作了一个自定义类型:

type ID uint

func (id ID) MarshalJSON() ([]byte, error) {
    e, _ := HashIDs.Encode([]int{int(id)})
    fmt.Println(e) /// 34gj
    return []byte(e), nil
}

func (id *ID) Scan(value interface{}) error {
    *id = ID(value.(int64))
    return nil
}
Run Code Online (Sandbox Code Playgroud)

我使用HashIDs包对我的id进行编码,以便用户无法在客户端读取它们.但是我收到了这个错误:

json:为类型types.ID调用MarshalJSON时出错:顶级值后无效字符'g'

json marshalling go hashids

1
推荐指数
1
解决办法
6037
查看次数