How does Texture2D.CreateExternalTexture work?

I would like to create and update a texture in a C++ plugin in order to build an Interface to a GPUDirect enabled professional video card.
What I have already figured out is the way from Unity/DX11 to video.
Now I need to figure out how to capture video.
Therefore I need a way to write texture data into a texture and use that texture in Unity.
I thought Texture2D.CreateExternalTexture would be the way to do this, but whenever I try to use it, I get a hard crash from somewhere inside an internal Unity function.

This is what I do:

IntPtr retVal = Marshal.ReadIntPtr(GetTexture());
		if(retVal.ToInt32() != 0)
		{
			inputTexture = Texture2D.CreateExternalTexture(1920, 1080, TextureFormat.RGB24, false, false, retVal);
		}

This is the Call Stack:

 	Unity.exe!TexturesD3D11::TextureFromShaderResourceView(ID3D11ShaderResourceView * resourceView, ID3D11Texture2D * * texture) Line 146	C++
>	Unity.exe!TexturesD3D11::RegisterNativeTexture(ID3D11ShaderResourceView * resourceView) Line 160	C++
 	Unity.exe!GfxDeviceClient::CreateExternalTextureFromNative(int nativeTex) Line 3108	C++
 	Unity.exe!Texture2D::InitTexture(int width, int height, unsigned int format, int options, int imageCount, int nativeTex) Line 469	C++

What am I doing wrong?

Did you ever get this working? I don’t think you want to do a ReadIntPtr - that reads an integer from the memory address that you pass in. What does your GetTexture() function return?

It looks like you are using D3D11, so you should be passing an existing ID3D11ShaderResourceView pointer to CreateExternalTexture. You’ll need an IntPtr that is really a pointer to an ID3D11ShaderResourceView, which you should have created in native code somewhere (e.g. in your native plugin).