Inspired by a recent newsgroup thread and my latest experiments in Clarion –> DotNet interop I have put together a simple program that shows you how to use the Zeta Color Editor from a clarion app!
The Zeta Color Editor is from an article in The Code Project and I have adapted it slightly to include a “Clarion Code” entry control as well as the “HTML code” it comes with. You may remember this control from the awesome InsertClarionColor addin.
This is the complete C# code used to call the Zeta Color Editor:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
using System; using System.Drawing; using System.Windows.Forms; using RGiesecke.DllExport; using ZetaColorEditor.Runtime; namespace ColorPicker { internal static class UnmanagedExports { [DllExport("ShowColorDialog", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)] static Int32 ShowColorDialog(Int32 lastSelectedColor) { string colorstr = string.Empty; using (ColorEditorForm cd = new ColorEditorForm()) { ColorConverter cc = new ColorConverter(); cd.SelectedColor = ColorTranslator.FromWin32(lastSelectedColor); if (cd.ShowDialog() == DialogResult.OK) { return ColorTranslator.ToWin32(cd.SelectedColor); } } return lastSelectedColor; } } } |
The clarion declaration looks like this:
1 2 3 |
MODULE('ColorPicker.dll') ShowColorDialog PROCEDURE(LONG lastSelectedColor),LONG,NAME('ShowColorDialog'),PASCAL,RAW,DLL(TRUE) END |
The zip file contains a clarion 8 solution (app file, etc), compiled exe for the impatient, the C# wrapper (ColorPicker.dll) and the ZetaColorEditor.dll. This should be everything you need to do your own testing. The original source for the ZetaColorEditor is found at the Code Project link at the beginning of this post, my customisations can be found at the clarion-addins google project page.
Download: | ![]() |
---|---|
Version: | 0.1 |
Updated: | September 20, 2011 |
Size: | 852.29 KB |
Downloads: | 691 |
Tags ___ interop
Comments: 6
Brucedadafdaf
| #
What is required to get this working an a machine running windows 7 x64?
Reply ___
brahn
| #
It should work fine. Are you having any specific issues?
Reply ___
bruce
| #
In the color picker example every time I press the button to select the color (ie call the dll) the program just hangs. I have used the unmanagedexports to expose my own static methods in a C# dll and get the same result. If I run the program on a 32 bit windows everything run perfect, but when I run on a 64 bit system the program just hangs (I can see the program in the Task Manager Process list, but nothing happens)…any ideas will be greatly appreciated!
Reply ___
brahn
| #
Hi Bruce,
That sounds weird. I just tested here on a 64bit system and it works fine. Can you confirm that the correct .NET framework version is installed on the x64 machine? Is it the clarion program that is hanging or when you click on the [Select Color] button that calls into the .NET code?
You might want to also look at my two most recent articles here:
http://www.clarionedge.com/clarion/clarion-and-net-interop-without-com.html
http://www.clarionedge.com/clarion/unmanagedexports-nuget-package.html
Reply ___
Bruce
| #
I have .net frameworks 2 to 4 installed on this machine(x64). The clarion app compiles ok and runs but the form looks distorted (eg no text on the button) and when I click the [Select Color] button the program crashes. It happens when I just unzip and run the test program and when I recompile the dll, create the lib, and recompile the clarion app. I have upgraded to VS2012 now and have used the nuget unmanageddll package to create some of my own test dll’s and all with the same results.
Reply ___
brahn
| #
Send me an email from the contact form on this site (I just don’t want my email address in the comments here for the spam bots) and we can swap some screenshots to see if there is anything I do from that.
Reply ___