winscard.dll warm up - c#

first of all I want to specified that formaly i'm a java programmer, but now i have to move for a while to C# programming in visual studio 2010 express for building a piece of program which read and write to smardcard (sle4428). And I have a couple of question.
1) I've seen some documentation about the winscard.dll api in this url, but in the signature of the function there aren't the data type of parameter but only in or out. (Doh) Exists a way to unterstand which type I have to use?
2)Exists some code example of how initialize a communication, without searching in "google search code"
3) The custumer provided to me basic VB code, can I build something which I can use in a C# context?
Thnaks guys for any help!!!!

Hope this helps:
http://pastie.org/1527598

The URL you've provided actually does show the types. LONG WINAPI SCardGetStatusChange( __in SCARDCONTEXT hContext, ... means that the first argument is formally named hContext, and has type SCARDCONTEXT.
The same page links to another page with an example.
Whether the VB code is useful at all depends on whether it's VB.Net. That would show the correct P/invoke forms.

Related

antlr4 parser.prog in C#

In this question somebody asked about the C# equivalent for java ParseTree class in ANTLR4. That answer is clear for me, but I have a related, previous, question: which is the equivalent for parser.prog()?
It seems that the whole processing starts from this point, calling parser.prog(), and I must be doing some very wrong thing as I cannot find the method prog() in myGrammarParser class. I've searched the github source for its base class Parser, but no prog() Method here neither.
I did some guessing, just in case the method had a different name, but no luck.
I think I'm moving back to ANTLR3, as I found some working example for ANTLR3 targeting C#. It's a pity that it's so hard getting this to work.
Thanks in advance.
The prog() method was created because the grammar contains a rule prog. If the starting rule were named something else, e.g. compilationUnit, then you would call the compilationUnit() method to parse the input.
This particular aspect of ANTLR did not change between ANTLR 3 and ANTLR 4.

C# <--> VB.NET DLL Conversion

I am a VB.NET developer and I was trying to use this library called Raw Input Sharp ( http://www.jstookey.com/arcade/rawmouse/ ) which allows me to receive raw data from multiple mice at once. The library was originally written in C# but due to the fact that I used .NET, it does not matter what the original language was.
I referenced it and got an error saying that the lib had multiple definitions with the same name. After about hours of struggle, I realized that in c# we have case sensitive while the opposite in vb. e.g. The structure RAWMOUSE coincided with the class RawMouse.
What do I do now?
Rename your struct or put it in a different namespace.
The answer was already provided by Hans Passant in https://stackoverflow.com/a/2302109/292411
For two identifiers to be considered distinct, they must differ by more than just their case.
So it seems, unfortunately, you cannot consume this library in its current form without running into that issue.

Code parsing C#

I am researching ways, tools and techniques to parse code files in order to support syntax highlighting and intellisence in an editor written in c#.
Does anyone have any ideas/patterns & practices/tools/techiques for that.
EDIT: A nice source of info for anyone interested:
Parsing beyond Context-free grammars
ISBN 978-3-642-14845-3
My favourite parser for C# is Irony: http://irony.codeplex.com/ - i have used it a couple of times with great success
Here is a wikipedia page listing many more: http://en.wikipedia.org/wiki/Compiler-compiler
There are two basic aproaches:
1) Parse the entire solution and everything it references so you understand all the types involved in the code
2) Parse locally and do your best to guess what types etc are.
The trouble with (2) is that you have to guess, and in some circumstances you just can't tell from a code snippet exactly what everything is. But if you're happy with the sort oif syntax highlighting shown on (e.g.) Stack Overflow, then this approach is easy and quite effective.
To do (1) then you need to do one of (in decreasing order of difficulty):
Parse all the source code. Not possible if you reference 3rd party assemblies.
Use reflection on the compiled code to garner type information you can use when parsing the source.
Use the host IDE's (if avaiable - so not applicable in your case!) code element interfaces to provide the information you need
You could take a look at how http://www.icsharpcode.net/ did it. They wrote a book doing just that, Dissecting a C# Application: Inside SharpDevelop, it even has a chapter called
Implement a parser to provide syntax
highlighting and auto-completion as
users type

C# Lua Parser / Analyser

first things first;
I am writing a little LUA-Ide in C#. The code execution is done by an Assembly named LuaInterface. The code-editing is done by a Scintilla-Port & the RAD / UI Interface is via the extensible IDesignSurfaceExt Visual Studio (one way code generation). File handling is provided by a little sql-lite-db used as a project-package-file.
So all in all i've got everything i need together...
The only problem unsolved is the parser / lexer for lua. I do not want to load & execute the code! I just want to parse the String containing the Lua code and get some information about it like function and global vars. I really don't want to write the parser completly myself... (I hate regex - I get the wrong all the time ^^)
Anybody got a link to a .net lua parser lying around?
Just to clarify - I only want to analyse the code at this point - I dont wnat to run it!
Thanks in advance!
Corelgott
Just for the record:
I went with a comibination of:
http://irony.codeplex.com/ - A Language implementation Kit that can be adapted to parse several languages. (Btw. this one got virtually no ducumentation what so ever... So code-comments no docs... but lots of fun...)
and a customized version of
http://luairony.codeplex.com/ - the Lua Syntax for irony (added some degree error tolerance)
But I gotta admin, both are pretty heavy stuff... and you kind of open up a box of new problems as well as lots of possibilities...
Cheers, Corelgott
This SO question's responses may be helpful.
Easiest way to parse a Lua datastructure in C# / .Net
Incomplete but:
http://luairony.codeplex.com/
This isn't quite what you're after, but maybe half of it can provide half the answer.
It converts Lua to C, by parsing the Lua to an AST. You could then extract the info you need from the AST. It's written in Lua, but you already know how to call that :)
Have look here: Lua recipes for LPeg
Maybe you can use one - otherwise I would look at using the extended BNF from the documentation.

How can I check the validity of a code file?

I'm trying to check the validity of a particular 'stand-alone' code file from within my C#.Net app. Is there any way that I can check the file and get a visual studio's style errors list out?
I'm only interested in running a basic check to ensure that the basics would validate. I.e. all variables are declared and method names are valid.
Is this at all possible?
If it's not the same as the referred to question (see my comment), you mention "VS style errors", consider using the CSharpCodeProvider. An example of its usage is in its documentation at MSDN.
Call the C# command line compiler (csc.exe)?
You can use static code analysis. There are a few libraries that enable this. The one that cones to mind immediately is StyleCop. It is written in .NET so you should be able to reference and use it through code if that is what you are looking for.

Categories