|
For information on P/Invoking native functions, see the DllImportAttribute documentation in the .NET Framework SDK. An example follows:
[DllImport("x.dll")]
private static extern long Test(
string f1, long f2, long f3, CDCAResult CDCAr); For the struct, you create the managed version just like you would re-create it in VB:
[StructLayout(LayoutKind.Sequential)]
public struct CDCAResult
{
public byte id0;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=17)]public string id1;
public long id2;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=41)]public string id3;
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
thanx for reply,
I have 2 question:
1- Is it the same declaration for Fixed-Length String and arrays which contains Fixed-Length String for exapmle:
F1 As String * 31
F2(0 To 7) As String * 41
2- when i use like this
[DllImport("x.dll")]private static extern long Test( string f1, long f2, long f3, CDCAResult CDCAr);
i get error, but if i use by reference like this:
[DllImport("x.dll")]private static extern long Test( string f1, long f2, long f3, [MarshalAs(UnmanagedType.Struct)] ref CDCAResult CDCAr);
it works without error, but still dosen't return correct value for Fixed-Length String in that structure.
any help really appreciated.
best regards
|
|
|
|
|
Sorry, didn't notice that the last param in your Function was a ByRef. Yes, the ref keyword would be necessary then. You could also use the out keyword if you don't need to pass an initialized struct into the function. That would save you from having to instantiate the struct before calling the method.
As far as the fixed-length string question, you'll have to jog my memory on the F2(0 To 7) As String * 41 syntax. It's been a LONG time since I programmed in VB.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I also got to thinking that the encoding could be the problem. Does this function that you're wanting to P/Invoke only support ANSI characters, Unicode characters, or either ANSI or Unicode depending on the operating system? Depending on what encoding it uses, you should add the CharSet property in the StructLayoutAttribute :
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct CDCAResult
{
} The SizeConst property in the MarshalAsAttribute will make sure that the offsets are correct for the String fields, so assuming that the rest of your fields where the values you were expecting the character encoding is most likely the problem.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
you are right, encoding was problem, that unmanaged dll dose not support Unicode, when i use Ansi, every things gose through.
I really appriciate your help and knowledge.
|
|
|
|
|
I am looking for info on creating application switches. After creating a shortcut in the users Startup folder, I want to start the application minimized.
Can anyone pass me a heads up ?
Thanks in Advance
**DAN**
|
|
|
|
|
|
Actually, you don't even need to parse a command line to start your app in a minimized state. just don't hard-code the Form.WindowState property and in the shortcut properties for your application, set the Run: setting to Minimized. You can also set this in the shortcut properties for an installer such as Windows Installer.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Anyone know of any components for writing CD's or DVD's in C# ? I presume there's no API's to do it in the language itself... I've found the MSDN one that does them in XP, but I want to be able to create video CD's, which this will not do.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
|
Thanks - got that, but it doesn't do what I want. I edited my post to clarify, so I guess you didn't see it, but I added that what I want is to burn VCD's or movie DVD's.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I'd love to know exactly how DVD authoring works, but I don't think a lot of it is public information. I'd love to make a cheesy utility (cheesy in that it's not WYSIWYG GUI etc.) that took an XML file and created a proper DVD image.
If you find some good specs on DVD's let me know.
A decent place to start looking at all this stuff is doom 9.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
Christian,
Your post got me searching after work. I've wanted some good DVD authoring libraries for a while, and like I said in my other post, I'd love to be able to make something that simply used XML as input and created a DVD. It turns out, someone else is many steps ahead of me.
I found a pretty cool project on SourceForge. Take a look at this project. They've basically created a console application (Win32/*nix) that takes an XML file as input and generates a DVD. It relies on other console apps (it's very *nixy like that), but it appears to actually get the job done.
It's not exactly a library, but the source code is available and the application in general seems very ripe for automating.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
Cool - thank you.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
The VCD format allows one to place data on a disc without CRC checking thus u can fit a full 800mb on an 80min cd (like an audio cd). I have tried to make VCD's in the past, but with no luck though.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
So in other words, just duplicating the file format of VCDs and burning them won't work ? Damn.
I've made heaps of VCD's that worked fine, just not programatically.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Looking for some help on how to print a custome page size. What I have is a third party pdf creator which is set up as a print driver in which you select it just like a printer and then send it a print doc(document.print()).
The problem is that when you select the paper size it does not retain the selection and always goes back to the default size. From what I have read this is a know bug in .net and the only fix in win32 api's. I am not familiar with how to do win32 api call in .net and am looking for any help I might be able to get. Fairly new at this stuff so any code would help.
lostegg
|
|
|
|
|
We have discussed this here a LOT in the last week or so. Please search the comments for the discussion of custom page sizes.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi. I'm a relative newbie with C#...I have some custom controls that are snarfed code from a co-worker (the only other C# code in our workplace).
I have created a windows control library project, added the code to it, and compiled it to the dll. Now I have gone to the custom controls and added them to the pane by selecting the dll file. But when I try to drag the control on to the form it gives me an error:
An exception occured while trying to create an instance of CTSSExp.Controls.ExplorerControl. The exception was "null" is not a valid value for 'control.'".
CTSSExp.Controls is the namespace the control is in and ExplorerControl is the name of the control.
Any suggestions?
Thanks.
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|
|
yeah - try to avoid cut and paste coding, it leads to errors. Also, avoid the form designer, that's not programming, and the designer really screws with your aspx HTML, sometimes making it invalid and often making it unreadable.
You should put the custom control into a project and use it from that project in order to eliminate any errors, then try putting it into a dll. That way, you are establishing that it works one step at a time.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
You are right about cut/paste coding...but in many work environments, its common practice.
However, I did put it in a sperate project (control library template) which compiles (no errors) to a dll.
I then add it to the form designer (add/remove and select the dll file), but when I try to get it after that (it shows up in custom controls tab on the toolbar) and drag it into the form I get that error I mentioned.
I'm sure its something simple...I'm just new to controls and still do not have a "lot" of experience with Visual Studio.Net and the .Net way of doing things.
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|
|
KingTermite wrote:
You are right about cut/paste coding...but in many work environments, its common practice.
In workplaces populated by idiots. Seriously, if you know it's bad practice, why do it ? Are you GUARENTEED to work in that place forever ? It's just self preservation to learn to do things the best way you can. If your workplace has components it wants reuses, they should be packaged in a dll to start with, and that project should be the only place the controls are modified, via source control.
KingTermite wrote:
However, I did put it in a sperate project (control library template) which compiles (no errors) to a dll.
So there are no compile time errors. I got that before. What does that have to do with run time ?
KingTermite wrote:
I then add it to the form designer
Like I said, don't. The form designer is the tool of idiots. Create a form, play with the designer, then go back to your HTML and see how much it has been screwed with.
KingTermite wrote:
I'm sure its something simple...I'm just new to controls and still do not have a "lot" of experience with Visual Studio.Net and the .Net way of doing things.
Sure - that's why I suggested a couple of steps whereby you can elimanate some factors, and some bad practices, and figure out what the problem is.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Christian Graus wrote:
In workplaces populated by idiots. Seriously, if you know it's bad practice, why do it ? Are you GUARENTEED to work in that place forever ? It's just self preservation to learn to do things the best way you can. If your workplace has components it wants reuses, they should be packaged in a dll to start with, and that project should be the only place the controls are modified, via source control.
No need to be so one-sided....we are not a workplace run by idiots...in fact we are at SEI level 5. Cut/Paste IS a level of reuse. It's called salvaged reuse. We do package "planned" reuse into a dll or other such libary, but my long term intentions are to modify and likely extend this control once I've got it working in the first place.
Now....what HTML are you talking about? I would skip the form designer if I knew how. I need to know how to put the control in if I'm going to do that. I was trying it from the form designer because I thought that was the proper method.
Thanks for trying to help...any more detailed info would be appreciated.
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|
|
I never use the form designer either. I click on the tab at the bottom that says "HTML" and go from there. It does save a lot of headaches in the long run.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
KingTermite wrote:
Now....what HTML are you talking about?
Any aspx page is has a .aspx file and a .cs file. The cs file is your code behind, the aspx file is your page, containing all your HTML, including the asp: tags that denote controls. When you're in the form designer, at the bottom of the page is a 'html' tab, if you click on it, you can hand edit the files. This is definately the way to go, and you should set up your preferences to always go here instead of the designer, for the reasons I mentioned.
And if it were me, I'd create a new control in a project, then copy and paste the html and C# code into it, then change the namespace of the class to match the project, and try to use the control in a page. Unless it's a server control, that's just a cs file, but I'd do the same with that. Not least is the fact that you could then set break points and step through the constructors, etc. to figure out what is going wrong.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|