Baiting title I know, but I’m am a C# fan-boy.
Anyway Shannon shows again that ‘cool-stuff ™ can be done in Java‘ with his newest synth WebGuitar.
Baiting title I know, but I’m am a C# fan-boy.
Anyway Shannon shows again that ‘cool-stuff ™ can be done in Java‘ with his newest synth WebGuitar.
The book is old 1981, but it’s still an interesting read.
Funest example in the book, starts like this:
Mole Ltd, installed a small desk computer on 1 May 1979 at a cost of $18,750 ….
how many K for small desk computer….
Also nice old-school 50 cents on the cover…
It effects us all.
We extended our legacy C++ DCOM application last week, and when the developer wrote the C#.Net end to call the new method, we were getting the error:
System.Runtime.InteropServices.SafeArrayTypeMismatchException
The developer that had added the method stated it worked, and pointed to his Delphi test app that worked happily.
Reviewing the method code it all looked fine. Single stepping through the code there where no problems.
The help for this exception says:
The exception thrown when the type of the incoming SAFEARRAY does not match the type specified in the managed signature.
But as we are dynamically calling the method like this:
objAddType = Type.GetTypeFromProgID("DCOM_OBJECT_NAME.COMPANY_CLASS_A");
objAdd = Activator.CreateInstance(objAddType);
object[] input = {};
object result = objAddType.InvokeMember("MethodName", BindingFlags.InvokeMethod, null, objAdd, input);
There was no was no signature.
This is for this Method:
VARIANT CompanyClassAObject::MethodName(void)
{
VARIANT vaResult;
VariantInit(&vaResult);
SAFEARRAY* sfa = GetSafeArray();
vaResult.vt = VT_UI1 | VT_ARRAY;
vaResult.parray = sfa;
return vaResult;
}
with the body of GetSafeArray looked like:
SAFEARRAYBOUND sfabounds[1];
sfabounds[0].lLbound = 0;
sfabounds[0].cElements = bytes_needed;
SAFEARRAY *sfa = SafeArrayCreate(VT_I1, 1, sfabounds);
if(sfa)
{
void *data;
if(SafeArrayAccessData(sfa, &data) == S_OK)
{
memcpy(data, buffer, bytes_needed);
SafeArrayUnaccessData(sfa);
delete buffer;
return sfa;
}
}
The problem ended up being that the SafeArray is created as VT_I1
type but when it is put into the variant type it was typed as VT_UI1
. So the .Net runtime was picking up the conflict and correctly complaining, and once you know what the error is, the exception message make sense. Funny that!
Setting the SafeArrayCreate to use VT_UI1 and every thing worked.
I have just swapped from NewsGator Sync to Google Reader Sync, so my shared feeds has changed, the link is also on my links section on the right…
Build 1.0.19 has been released. Fixed in this version:
Enjoy.
Build 1.0.18 has now be released Two fixes:
As always let me know if you have or find any issues.
A very interesting and engaging talk.
Found via Presentation Zen where Garr often links to great TED talks, and this is the major reason I subscribe to his feed.
I picked up a copy of Lex & Yacc off TradeMe the yesterday, and I’m quite excited.
I’m hoping it will help me get my head around parser writing, for my still to-be revealed side project…
For a while now I have been working on a side project to add editor support for Erlang in Visual Studio.
I have a Google Code project for it, and it currently has syntax colour highlighting, but I was getting stuck with writing othe parser.
This is where the project has stalled over the last few months as I have been reading lots.
Originally I was basing my work on Lua Langage Pack for Visual Sudio. This package is a C# based plug-in that uses the CSTools project by Malcolm Crowe.
With the help of Code Project documents, MSDN and Blogs I slowly got a plug-in that has colour highlighting working (if you run it in the debug Visual Studio).
I was also reviewing how the IronPython project does it’s parser, but that used seemed to use python to do some parsing.. so
I then was trying to get Antlr to work, via AntlrWorks, but was banging my head on the debuggers limited support.
The next problem was how do I actually define the grammar for Erlang.
Erlang ships with a grammar defined in yecc, it’s version-thing of yacc. So I started translating this to Antrl but was getting left-right recursion errors, even though the problem was not the standard definition of left-right recursion problem. Yecc is recursive decent as Erlang does recursion so well, but this was not playing well with Antlr. I then discovered I was looking at a subset of the Erlang gramma, and the full yecc gramma was huge, so hand translations was not an option.
So I then found the yecc grammar for yecc, and thought that I could hand roll a C# recursive decent parser for yecc, which would allow the auto-writing of a proper grammar for CSTools. But I wasn’t so keen on the .dll dependency of that tool chain.
I started reading the dragon book (Compilers: Principles, Techniques, and Tools) around this time, so was starting to get my head a little better positioned.
I then stumbled on to the Irony project which is a Visual Studio language development framework. Eek they have most of what I was trying to workout how to-do, mostly worked out. But they have their own lex and yacc like tools. This project also refers to the Visual Studio’s lex and yacc tools called MPLex and MPPG (distributed in the Visual Studio SDK)
I have just found that the newer version of the Lua project for Visual Studio 2008 uses the Irony project, and is hosted on CodePlex.
So I was getting keen again to work out how to use lex and yacc correctly, thus why when I saw this book for $3, I bid and anxiously waited to se if I’d win. Of the 19 counted page view on the auction, 17 were mine.
So I’m half way through the first chapter and have just realised I don’t need to write a hand parser of yecc, I just need to write a lex parser that translates yecc to yacc, and rebuild that with MPPG to get a C# Erlang parser that is not hand rolled. Which means if the Erlang language changes, I can just re-run the whole process on the new gramma, and still be compliant.
Funniest story from the development team over that partition.
The team was having issues with network settings on Windows Vista, so one developer asked a question on Stack Overflow regarding the problem. A day later the team lead after doing some Google research sent an internal emailed to the group, suggesting the Stack Overflow question with a note “look someone else is having our problem, and seems to have some leads…”
Oh the humour when it was pointed out that the question asker had a handle that was the same as the full name of a team member.
Also on a side note: I’ve been not been blogging much recently, mostly because I have been taking all those spare micro moments that previously I’d have bashed a post up, to read/answer Stack Overflow questions, it’s so addictive