|
Sorry, thought I'd read somewhere on MSDN that you can easily include classes defined in C++ by declaring them with the __gc managed extension, haven't really looked into it though.
I've already tried the [MarshalAs(UnmanagedType.LPWStr, SizeConst = MAXCHARS)] attribute and again there was no rejoicing. In fact I think I've just about tried everything, including adjusting my seat position and the way I tie my shoe laces but none of it seems to work... maybe a low carb diet might work... I'm really grasping at the proverbial straw here. The only way I see out of this at the moment is to pass in arrays of the same size, one for each variable in the structure that I need to set. That's really filthy, I'm going to wash my mouth out with carbolic soap, but if it works, it works.
|
|
|
|
|
You can, I just don't know why you brought it up in this discussion. If you declared your struct as a managed struct, then you wouldn't need to P/Invoke anything anyway.
One thing you could try is to fix the memory address of the array before passing it, also changing your first param to IntPtr , something like this:
GCHandle handle = GCHandle.Alloc(myArray);
MyMethod(handle.AddrOfPinnedObject(), ...);
handle.Free(); This makes sure that the GC doesn't move it while in use, which can lead to all sorts of problems.
I do a lot of unmanaged interop and frankly have never had this problem, so I'm sorry I can't be of more help. Believe me, it's bugging me now, too.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
More of an aside, in relation to your mention of instance methods, but it seems to have led to a possible solution by avoiding the use of P\Invoke by using the __gc declaration. In fact, with it being my own structure, there's no reason not to. Thanks again, I'll try this in the morning (this is the UK and it's nearly 23:00 and I've been staring at the screen for so long the walls of my house are covered in text). I'll update you to let you know how it goes but I've got a feeling it'll work.
|
|
|
|
|
Hello Heath,
after some time away and quite a bit of coding to wrap up my dll in C++ managed extension stuff I have perfect interoperability. The managed extensions make interop virtually seemless and the P/Invoke stuff more or less pointless for C++ stuff unless your only passing simple datatypes. Thanks for your help.
Luke
|
|
|
|
|
I'm still suffering from flickering problems and glitchy transparent corners (they show the background, not the controls underneath).
I think the solution to both problems could be to make a buffered bitmap. But i've no idea how to buffer the Theme as it's drawn directly to the screen.
I played around with attempting to use the bitmap graphics object to create an hDC handle, but it didn't work, i just got black.
Any ideas what I could do?
Cata
|
|
|
|
|
You can enable double-buffering for a control easily by calling the following in your constructor:
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true); This tells the CLR to call OnPaint in a separate thread to draw to an off-screen bitmap. When the painting is done, the image is flipped to the device context. Or at least, it's something close that that. This saves you from having to swap everything yourself and from using an incompatible bitmap if not created correctly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I already tried the Double Buffer bit, but it appears that it doesn't work with API called window themes. I just get black.
Works fine if I am not using themes though. :/
|
|
|
|
|
Oh, also pay attention to the PaintEventArgs.ClipRectangle . You don't always need to paint everything. In larger controls, this can make a difference. Determine which elements of your control need painting using that property and only repaint those. This is something commonly overlooked but necessary for better performance regarding painting your UI elements.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I've found that i can reduce flickering dramaticaly on the left and top edges by overriding the on paint event, and not drawing the background. The right and bottom areas, where the re-size takes place, are still affected though, so i'm not entirely sure what to do about that. (This LOOKS like when i re-size, the background is rendered before the move, and then drawn over, causing the flickering, despire using the SuspendLayout method).
However, this causes anomalies on the corners where the background displays the desktop / window behind, as the alpha blending goes straight through the non rendered background.
I'd really be interested in rendering the theme bitmap, over the background control images, to a buffer first. If that's possible.
|
|
|
|
|
It appears that it only flickers on Right and Bottom when i shrink the object on resize. Making it larger looks fine.
Moving still produces minor problems.
The lack of background rendering still causes weird stuff to happen to the transparent parts tho.
|
|
|
|
|
Hi.
If I have an object "x", in MFC I can create an array of objects "x" with CObList or CPtrList. In C# how could I do that?, what collection should I use?.
ArrayList??.
My object should be derived from some interface like ICollection or IDictionary?.
My object, (named CParameter), for now, have only two data members: ID and Description, and I have another class, (named CSistem), that have a list of objects CParameter.
Thank you.
|
|
|
|
|
You can create an array just like you can in C/C++:
x[] xes = new x[100]; An array (derives from Array at runtime) implements IList , which implements ICollection , which implements IEnumerable ). You could also use an ArrayList which implements the same interfaces. If you want to have your own typed collection, you could extend CollectionBase which implements all those interfaces or just make one from scratch.
Also, don't prefix your classes with "C". This old notation should not (i.e., that doesn't mean "must not") be used in .NET development. If you look at the FCL (Framework Class Library), you see that there is no Hungarian notation. This is to keep everything consistent, which is important in many development environments (especially RAD environments).
See Naming Guidelines[^] in the .NET Framework SDK for more information.
To serialize arrays, you have two options. One is runtime serialization, and is the most powerful. This uses classes and other elements from the System.Runtime.Serialization namespace and child namespaces. Both a BinaryFormatter and a SoapFormatter are provided in the FCL.
There's also XML serialization, which uses classes and other elements from the System.Xml.Serialization namespace. This is less powerful and offers less control (if you stick to what the documentation says and don't implement the IXmlSerializable interface).
For a discussion of both - and examples using each - see Serializing Objects[^] in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
To add to Heaths comments....if you are serializing the objects for the purposes of remoting, then all you need to do is define the ArrayList and add the attribute [Serializable].
The BinaryFormatter will handle the serialization and deserialization of your request and you do not need to implement your own ISerializable interface code.
___________________
Forgoing antagonism and separation, one enters into the harmonious oneness of all things. Lao Tzu
|
|
|
|
|
I'm using ClientRectangle to clip my mouse pointer, and while it works, the rectangle is slightly offset from the actualy screen representation by the ammount of the docking.
Where the top left corner should begin at 4,4 due to the 4 pixel docking i am using on the parent control. This element is ignored and it is actualy clipped at 0,0.
Is this a bug?
Cata
|
|
|
|
|
Why should it be a bug? It's doing what it should. The client area is correct. You just need to account for the DockPadding on your control which derives from ScrollableControl (Panel , UserControl , et. al.).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
We have a fairly large project which is a WinForm project.
After working on this project after awhile we began to hit a nasty situation where Intellisense lost it's intelligence, code lost its' color coding, and the Intellisense popup boxes did not display the objects namespace. At its worse, Intellisense, automatic formatting, and all color-coding completely failed. It left us with having to code blindly and hoping the code would compile correctly.
The bigger bugger of it all is that it seemed to happen eratically after working in the IDE for hours-on-end doing continuous change/build/debug cycles with no regular, re-creatable scenarios. We usually had to reboot to try and fix it.
Last week we finally nailed the bugger, reproed it on an un-managed machine and on an MS-built machine which led to the discovery of the cause. Talk about oblique:
If you are building a WinForm application
AND you are adding third party controls
AND the third party controls update the license.licx file
There is a known bug that VS will randomly append an additional
blank line to the end of the file. When this happens, it will
lead to Intellisense going brain dead!!! This will not be fixed
until Widbey.
Workaround: open your license file and delete the extra line.
___________________
Forgoing antagonism and separation, one enters into the harmonious oneness of all things. Lao Tzu
|
|
|
|
|
Interesting. I've had that problem many times in the past, too. Fortunately, we don't often prompt changes to third-party controls (they're pretty much set in place now), but I usually just restarted the IDE and called it good. It is interesting to know "why" (well, the cause anyway) it happened.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It was a bugger to locate. We pretty much determined that if you add third party controls and this bug occurs, it could be quite a while before you encounter the problem. But all you need to do is add a new form to the existing project (even if it only uses built-in controls) and you are screwed and tattooed.
___________________
Forgoing antagonism and separation, one enters into the harmonious oneness of all things. Lao Tzu
|
|
|
|
|
You should have searched Google Groups because we had the exact same problem this summer and we spent quite some time to figure it out (nobody else figured it out before us according to the newsgroups)...
We decided to post the solution there "for the record"... Next time, spare yourself some sweat and http://groups.google.com
|
|
|
|
|
Yes, well, we were working with onsite Microsoft people. I had mission critical apps to work on and left all of the problem resolution to them. And while I use Google extensively for all types of searches, I usually do not do any searching of Google Groups.
___________________
Forgoing antagonism and separation, one enters into the harmonious oneness of all things. Lao Tzu
|
|
|
|
|
Google Groups is your friend! I search it more often than the web when I have problems!
|
|
|
|
|
Hi,
I’m new to C# and the .NET world. Can anyone tell me how to create a master project populated with sub projects? Ideally I’d like to have my master project depend upon a couple sub projects (like a common library, user info, and database info). How can I create this structure in .NET? Once this structure is created, how do I add project dependencies?
If anyone can show me an example of this that would be great.
Thanks
|
|
|
|
|
If we're talking VS.NET, you should create a Solution to hold all these Projects. If you don't have a Solution open when you create a new project, VS.NET will create one for you.
When you select File > New > Project, the New Project dialog has a pair of radio buttons Add to Solution and Close Solution. Select Add to Solution to keep this project as part of the whole solution. If you have a project you want to add to an existing solution, choose File > Add Project > Existing Project.
To set up dependencies, use the Projects tab of the Add Reference dialog, rather than the .NET tab.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
To add to what Mike said, the reason you use Project references is because it automatically sets up build dependencies and uses the latest version of the dependent assemblies.
Also, in larger, multi-project solutions, DO NOT use automatic versioning (i.e., set AssemblyVersionAttribute so that it doesn't use an asterisk (*)). You can quickly loose control with versions being different, especially when multiple developers are working on the solution.
In .NET, version numbers matter. If you binding against assembly A, version 1.0.0.0, then when assembly B (has a dependency on A) loads, assembly A, version 1.0.0.0 better be there. You can use the .config file and the <assemblyBinding> section to redirect these versions or use a publisher policy (a specially named assembly that goes into the GAC), which is primarily for upgrading your application (so long as backward compatibility is maintained). You certainly don't want to have to worry about this when developing.
If you want to use automatic versioning, expect problems. You can get around them, however. Lets say that each developer has an application test directory (or even a shared one). Using the assembly A as a dependency of assembly B example (lets say B is a .exe), you could use a .config in the same directory as B.exe like this:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="A" publicKeyToken="0123456789abcdef"
culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535"
newVersion="1.0.1556.500"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration> This will redirect the assembly binding from whatever version it is to version 1.0.1556.500, so make sure you update those config files when you drop a new version of assembly A in the app directory.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|