The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
I have the basis for what might be an interesting article in and of itself within my MIDI library.
There's a very tricky call i have to make that relies on passing essentially variable length structs, and consequently, the .NET marshaller cannot handle it out of the box. Instead of using StructLayoutAttribute and MarshalAsAttribute to mark up your structure and p/invoke function calls, you basically need to use StructLayoutAttribute and then use the Marshal class methods to copy the variable length portion in manually.
I don't know how many people have run into P/Invoking into C style libraries that take variable length structs, so is anyone interested in this?
I'd rather put this out there up front before I spend time and effort on an article that nobody cares about, and this is kind of arcana.
Edit: Big thanks folks. Your responses let me know there was some interest and I'm in the process of writing it.
My biggest achievement along the same lines I can't show in code, a) because it was commercial - wrapping a c++ PGP library and creating a C# layer for it, b) iirc it was relatively 'simple' structs etc
I've been doing p/invoke so long and C coding before that that I kind of forget what people don't know when it comes to it. I didn't want to recover beginner P/Invoke stuff but let me know if I didn't explain something very well, when you get a chance to look at it.
I was just teasing earlier, I'd have never made you type that much. What kind of monster do you take me for?
I was thinking about MarshalAs while reading about the MIDIHDR structure definition. Actually lol'd when I got to this part
I thought the article was really interesting. I've done p/invoke and marshalling stuff before but I learned quite a bit here. I had no idea about the StringBuilder trick for example I really enjoyed it!
Here you go. If I didn't explain something regarding how to do this technique very well, let me know and I'll append the article. I've been doing P/Invoke so long I may take for granted things people don't know.
I have read it, but another thing is to understand everything
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.