|
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.
Real programmers use butterflies
modified 4-Jul-20 7:37am.
|
|
|
|
|
As you and I have discussed, I think it would be worthwhile .. sure, I can pull apart your code and but that won't necessarily make it obvious
This will become another resource, along with Luc Pattyn's Article: P/Invoke, part 1 and to a much lesser extent pinvoke.net: the interop wiki!
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'd read it
|
|
|
|
|
I posted it here: P/Invoke Jujitsu: Passing Variable Length Structs[^]
I hope you enjoy it.
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.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote:
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!
|
|
|
|
|
That's good to hear. I'm glad you enjoyed it.
And thank you!
Real programmers use butterflies
modified 4-Jul-20 21:13pm.
|
|
|
|
|
I'd certainly read it
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
P/Invoke Jujitsu: Passing Variable Length Structs[^]
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.
Real programmers use butterflies
|
|
|
|
|
Just read it - very cool stuff going on in there - I love this kind of lowish level tech - well done
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
pkfox wrote: I love this kind of lowish level tech
back in my day (1986 or so) that was called programming.
Seriously though, I'm always glad to know when someone appreciates one of my articles. thanks
Real programmers use butterflies
|
|
|
|
|
I have read it, but another thing is to understand everything
M.D.V.
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.
|
|
|
|
|
I welcome questions. I really wish it was something i could demonstrate with puppets.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: I welcome questions Good to know
M.D.V.
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.
|
|
|
|
|
I have a background in bit twiddling on 8 bit and 16 bit machines in asm and later C so when I see a struct I automatically visualize its layout in memory. It makes doing p/invoke easy but hard to explain because i take things for granted that other people maybe struggle with.
I think it hurts my writing. So I'm serious, when you get a chance, if the way I'm writing and presenting this material makes it difficult for you or other readers to understand it, you are the most helpful resource around to me and I'd love your help in helping me explain it better, if that makes sense.
And if you're not interested or you don't have time that's okay too.
Real programmers use butterflies
modified 4-Jul-20 18:24pm.
|
|
|
|
|
Have you seen the second sentence of my signature?
I know what you mean.
I'll re-read it and give you a feedback, but it might get some time.
M.D.V.
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.
|
|
|
|
|
okay, fair enough.
Real programmers use butterflies
|
|
|
|
|
First make it work
Then make it work *fast*
Then find out why it doesn't work anymore
Then ask for an actual test budget/timeline for projects.
Then get blown off.
Then ask a coworker to look at the code
Then hack it to work
Then make it work with a new feature
Then make management happy until the customers start calling because it blew things up.
Then ask (again) for an actual test budget/timeline for projects.
Then make it tested.
Then make it work
or something like that.
(cowboy coding in the dotcom boom 1990s trying to serve way more pages than servers were worth in those days and on impossible timelines)
I do like that companies I worked for started realizing that actual development lifecycle and testing was important, though sometimes it took some failed projects.
those were the salad days.
I'm sure the above has many variations, and everyone can come up with one. We all have war stories. It's what makes it fun.
Real programmers use butterflies
|
|
|
|
|
This variant happens a lot:
- Make a super techy proof-of-concept, fast as Elephant!
- Made it. [Not me personally but I saw it happen.]
- They sold it.
- They sold it again and again and...
- Now add a bunch of features!
- Yihaa!
- Why the Elephant is that so hard? Who the Elephant wrote this pile???
"If we don't change direction, we'll end up where we're going"
|
|
|
|
|
That's actually pretty good result, considering it made it through the first sales cycle.
Real programmers use butterflies
|
|
|
|
|
Well I was a bit inaccurate there. It was sold before development and paid on delivery.
"If we don't change direction, we'll end up where we're going"
|
|
|
|
|
You must be with the advanced team.
- Discuss a feature in a meeting.
- Decide it is feasible.
- Manager tells the sales team.
- Submit a budget and time frame for development.
- Sales team sell the feature as completed.
- Manager wants to know why the feature has not been completed.
- Ask management for budget approval.
- Sales manager goes ballistic because he has a pissed off rep and customer.
... it goes on and on and never gets better!
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
It's 2000, the peak of the telecom bubble. An all-hands meeting, maybe 250 people in attendance. My boss, the VP of Engineering, is Sri Lankan. Best boss ever. No nonsense, and no tolerance for corporate politics. Calls stuff like that boo-sh*t because Tamil lacks the ll sound in bull. But only in his staff meetings.
He gets up to speak and laments how hard it is to find qualified developers. He describes the people coming in for interviews, saying "We have lots of Joe Blows, but no Joe Blow jobs." Laughter, but probably a lot more than he expected.
Totally innocent. He would have been absolutely mortified if he'd realized the double entendre. Today, some snowflake would have gone whining to HR, and his job might be in jeopardy. Back then, no big deal.
|
|
|
|
|
At COMDEX in 2000 some coworkers (with our CEO) threw burning pizza boxes out the window of their hotel. I had nothing to do with that particular incident of debauchery, but there are others that happened during those couple of weeks that I won't mention outside of vegas. I was however, in the car when said CEO drove the rental car up a curb and blew out the tire, he drove it back on the rim and they gave him an SUV instead. Vegas is full of enablers/ Fun times.
Edited to make SFW. Apologies
Real programmers use butterflies
|
|
|
|