Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# or VB.NET as help to vfp for com objects 1

Status
Not open for further replies.

markftwain

Technical User
Jul 12, 2006
108
Hi experts,

It appears that there are many objects on windows 7 that are accessable to C# and not vfp (e.g., the inkAnalyzer). Is it possible to use c# or vb.net to create a com object for the inkAnalyzer that would expose its methods and events to VFP?

And if so, coming from a vfp background, which would be easier to use?

Your opinions are much appreciated. Thanks.
 
In VFP you'll need a COM ActiveX Control. It doesn't matter in whicht .net language this would be written.

One thing you could make us of is the vb.net Interop Forms Toolkit, which adds new project types to VS.NET for VB.net, in that respect that VB language has an advantage.


Actually under Win7 the corresponding DLLs are missing not only to VFP, but also to .net, you need to install the Tablet SDK to have these classes.

It also seems this is targeted to WPF only, as far as I googled. That would mean even if those classes are available in .net, you won't be able to make an COM Server or ActiveX control out of it, as those I think are limited to Winforms only. I might be wrong on that.

Another strategy might be to build something as a Silverlight application and run it embedded in a WebBrowser Control on a VFP form.

Bye, Olaf.
 
Hi Craig,

Nice to know, I'll keep that in mind. Sounds plausible if you keep in mind any activex control really is an embedded winform with it's own hwnd. So each activex control really is in it's own "world".

So, is there a dedicated c# interop toolkit or can you simply install the vb.net one and work with c#? I have only used that once and did only find interop projects in the vb.net category, as advertised in the toolkit description.

Bye, Olaf.
 
Thanks for mentioning this, craig.
This may come in very helpful in the future.

Bye, Olaf.
 
Hi Doug;

The conference looks great, but is long off. In C#, ActiveX controls can be made quite easy...but interfacing with VFP is a challenge.

How do you pass the foxpro form to an ActiveX component?

More details:

Defining a C# module as a windows form works well:

public partial class Form1 : Form
{
...
public Form1()
{
...
this.inkOverlay = new InkOverlay(this);
this.inkOverlay.Enabled = true;
this.inkOverlay.Stroke += new InkCollectorStrokeEventHandler(inkOverlay_Stroke);

this.inkAnalyzer = new InkAnalyzer(this.inkOverlay.Ink, this);
this.inkAnalyzer.ResultsUpdated += new ResultsUpdatedEventHandler(inkAnalyzer_ResultsUpdated);

...
}
}

However, after compiling as a com object (with no errors) from VS Studio 2008, trying to use essentially the same code with vfp like:

myInk = createobject("myInkAnalyzer") <---Yes! this works
myInk.make (inkOverlay.ink, thisform) <---No. Error.

Results in runtime errors of "interface not-supported" or ISynchronizeInvoke wrong type. Which quickly leads to threading issues.

I defined myInkAnalyzer basically like this:

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("myInkAnalyzer")]
public class myInkAnalyzer
{
private InkAnalyzer inkAnalyzer;
private Microsoft.Ink.Ink myink;

public myInkAnalyzer()
{ }

public void make(Microsoft.Ink.Ink ink, Form myform)
{
this.myink = ink;
this.inkAnalyzer = new InkAnalyzer(ink, myform);
this.inkAnalyzer.ResultsUpdated += new ResultsUpdatedEventHandler(inkAnalyzer_ResultsUpdated);
}

.....
}
}

Any help would be appreciated. Thanks


 
Hi Mark.

I haven't done much work passing VFP objects to .Net, but it looks to me like you're specifying the second parameter of Make incorrectly. Try using "object" instead of "Form", since the type of the VFP form isn't known to .Net.

Also, in reviewing the docs for InkAnalyzer ( its constructor doesn't appear to take two parameters, and even the first parameter must be an instance of System.Windows.Threading.Dispatcher. So it looks like the new statement needs to be looked at too.

Doug
 
Mark,

I don't understand what you're doing. Why would you pass a form to an ActiveX control? ActiveX controls are hosted on a form, frequently exposing some UI functionality.

It looks like what you're trying to do is create a COM server. You can't pass a reference to a VFP form to it because VFP uses a different object model than .NET. You may be able to use the Interop Toolkit to get it to work, but it really depends on what you are trying to do. I need more information to say if the Toolkit will work for you or not.

What is the purpose of the InkAnalyzer?



Craig Berntson
MCSD, Visual C# MVP,
 
In the overall scheme, it appears that the inkAnalyzer provides better handwriting recognition then vfp's inkEdit, so I thought I'd work with it some; it appears that C# works easy with the inkAnalyzer.

The problem I am having is getting a COM object created by visual studio 2008 to pass the vfp 9 hwnd windows handle correctly to the inkAnalyzer or inkOverlay or inkCanvas which they apparently need (???) for thread synchronization.

More details:

I have a vfp form that pops up and provides a grid that does a name lookup on a table of about 20,000 record as characters are typed in.

What I'm trying to get at is having the vfp form receive characters from handwriting on a wacom pad and have the actual handwriting image displayed on top of the grid. I have done this easy enough using the ActiveX library that VFP has access to, but can't get that same library to use the inkAnalyzer object nor have vfp detect the stroke events so I can move the grid.

I believe this can be done fairly easy in C#--if I could get the correct syntax.

So, what I have in C# is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace MyCustomInk
{
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("MyCustomInk.cInk")]
public class cInk
{
public Microsoft.Ink.InkOverlay oInkOverlay;
public void makeit (IntPtr hform )
{
// load and initiate the InkOverlay object
this.oInkOverlay = new Microsoft.Ink.InkOverlay();
this.oInkOverlay.Handle = hform;
this.oInkOverlay.Enabled = true;
}
}

}

which I would use from VFP 9 as

x = createobject("MyCustomInk.cInk")
x.makeit (thisform.hwnd)

x.makeit (thisform.hwnd) consistently fails with: "Interface not supported"

I have read everything I can find, but I'm missing something..

Thanks for any help.
 
Probably a bad choice for a name of an example method in my created cInk class.

What "interfaces" does the vfp "form" implement, if any? Or is there a way of adding an additional interface or wrapping the vfp form in an interface that .net would accept?
 
Also, a bit confusing...which should be used:

the InkAnalyzer Class is in System.Windows.Ink Namespace

with definition of:

public InkAnalyzer(Dispatcher synchronizingObject)

AND in


Microsoft.Ink Namespace

with definition of:

public InkAnalyzer(Ink ink,ISynchronizeInvoke synchronizingObject
)

Thanks

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top