NoLabel Posted September 6, 2013 at 12:51 AM Report #523581 Posted September 6, 2013 at 12:51 AM Olá, directo ao problema: -> Tenho uma aplicação em C# que vai executar uma função de uma .dll escrita em C++. Source da .dll: extern "C" { __declspec(dllexport) void WriteFile(lzo_uint8* source, int size) { FILE * fileToWrite; fileToWrite = fopen("test.gsd", "wb+"); if (fileToWrite) { fwrite(source, 1, size, fileToWrite); } fclose(fileToWrite); free(source); } } Nota: typedef unsigned char lzo_uint8; Isto é apenas para teste, óbvio que não é este o objectivo da .dll... Agora na aplicação em C#: [DllImport(@"GLZO.dll")] public static extern void WriteFile(byte[] source, int size); Aqui estou a importar a .dll e declarar a função. E assim é executada: byte[] g = ReadFile("raw/file.gsd"); WriteFile(g, g.Length); A minha questão como posso converter de byte[] (byte array) para um unsigned char*? Melhores cumprimentos
brunobola Posted September 7, 2013 at 11:18 AM Report #523752 Posted September 7, 2013 at 11:18 AM Tenta isto http://msdn.microsoft.com/en-us/library/system.text.encoding.getchars%28v=vs.80%29.aspx
NoLabel Posted September 7, 2013 at 02:36 PM Author Report #523761 Posted September 7, 2013 at 02:36 PM Já tinha tentado isso, não funciona. Deixo aqui para quem precisar, encontrei a solução: unsigned char*(C++) = IntPtr (C#).
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now