Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
12
Erster Beitrag:
vor 9 Monaten, 4 Wochen
Letzter Beitrag:
vor 9 Monaten, 3 Wochen
Beteiligte Autoren:
steve erts, Arie, David Egan, Fabrice Harari, Peter Holemans

Working with DotNetDelegate (solved!)

Startbeitrag von steve erts am 28.08.2017 19:43

Hi,

I'm working with a Magtek DynaPro Keypad device to encrypt Credit Card entries for a client. I've been successful importing the MagTek .NET assembly and using it to open and initialize the device and accept card number entry

Where I'm stuck now is how to write the code to use DotNetDelegate to get the result back from the device.

My calling code to the device looks like this.




// declare object

clMagtek is object MTPPSCRA

//open device

sDevice is UNICODE string
nOpen is int=clMagtek.openDevice(sDevice)

// request manual card entry
nStatus is int
clMagtek.requestManualCardData(60,1,31010003,nStatus)




From what I gather I now need to use a "DotNetDelegate" event to get the result back from the device. Here is the section from the device docs.

4.11 OnCardRequestCompleteEvent

Return event for requestCard.

public delegate void OnCardRequestCompleteEvent(String lpData);

Parameter : Description

lpData : A response string for the requestCard function.


I've looked at the Windev docs I'm really not clear on how to implement the callback function and several hours of mucking around hasn't seemed to get me any closer.

Can anyone help with this?

Thanks!

steve

Antworten:

Re: Working with DotNetDelegate

Hi Steve,


The DotNetDelegate() function should make this possible for you.
See http://doc.windev.com/en-US/?1000017052&name=dotnetdelegue_fonction

Cheers,

Peter

von Peter Holemans - am 29.08.2017 06:40

Re: Working with DotNetDelegate

Quote
Peter Holemans
Hi Steve,


The DotNetDelegate() function should make this possible for you.
See http://doc.windev.com/en-US/?1000017052&name=dotnetdelegue_fonction

Cheers,

Peter


I've seen the documentation. The issue is that, at least from my perspective, it's not terribly clear. The examples seem to bounce back and force between procedural and object methods and I'm having a hard time following. Especially as I do no Object based coding.

von steve erts - am 29.08.2017 14:11

Re: Working with DotNetDelegate

Hi Steve
I usually wrap .Net assemblies in their own class and do all my calls through it but essentially what you'll need is something like the following

CardRequestCompleted is OnCardRequestCompleteEvent dynamic
CardRequestCompleted = DotNetDelegate(MyRequestCompleted,"OnCardRequestCompleteEvent")


You will then need a procedure MyRequestCompleted(CardResult is string) where you can code whatever you need for the result

HTH

David

von David Egan - am 30.08.2017 05:36

Re: Working with DotNetDelegate

Quote
David Egan
Hi Steve
I usually wrap .Net assemblies in their own class and do all my calls through it but essentially what you'll need is something like the following

CardRequestCompleted is OnCardRequestCompleteEvent dynamic
CardRequestCompleted = DotNetDelegate(MyRequestCompleted,"OnCardRequestCompleteEvent")


You will then need a procedure MyRequestCompleted(CardResult is string) where you can code whatever you need for the result

HTH

David


Hi David,

Thanks so much. That got me quite a bit further. However, I'm now getting this error on execution.

Error at line 21 of Click BTN_Open_Device process.
DotNetDelegate function called.
Unable to create object ( assembly)
Unable to open assembly
Error returned by .NET Framework:
Could not load file or assembly 'file:///C:\My Projects20\Tourcube\Exe\Tourcube\' or one of its dependencies. The system cannot find the file specified.

Ideas?

Steve

von steve erts - am 30.08.2017 15:05

Re: Working with DotNetDelegate

Hi Steve,

most probably the MagTek dll cannot be found from the path. Maybe you have to copy it into your project exe directory. You may very well need to copy more than one dll. You can Google for ".net dependency analyzer" and find numerous tools which show you the 2nd, 3rd and other required dll's it needs.

von Arie - am 30.08.2017 19:11

Re: Working with DotNetDelegate

Hi Steve
It can't find the assembly at runtime so apart from the obvious (typos etc), it could be where the assembly is located. As Peter mentioned in another thread it seems rather 'flaky' in where it searches for the assembly. If it's not in your executable directory try copying it in there, we've found that's the most reliable.

David

von David Egan - am 30.08.2017 19:20

Re: Working with DotNetDelegate

The problem was that I had to install the .NET framework and now the code completes without error.

CardRequestCompleted is OnCardRequestCompleteEvent dynamic
CardRequestCompleted = DotNetDelegate(GP_MyRequestCompleted,"OnCardRequestCompleteEvent")

However, the "GP_MyRequestCompleted" procedure doe not seem to ever get called when I trigger event from device.

What am I missing?

von steve erts - am 30.08.2017 20:36

Re: Working with DotNetDelegate

Not getting errors but still having issues getting a response back.

Here is what my code looks like. (It is loaded in a button on a form)


// declare object

clMagtek is object MTPPSCRA

// declare delegate

CardRequestCompleted is OnCardRequestCompleteEvent dynamic
CardRequestCompleted = DotNetDelegate(GP_MyRequestCompleted,"OnCardRequestCompleteEvent")

//register delegate

clMagtek.add_onCardRequestComplete(OnCardRequestCompleteEvent)

//open device

sDevice is UNICODE string
nOpen is int=clMagtek.openDevice(sDevice)

// request manual card entry
nStatus is int

clMagtek.requestManualCardData(60,1,31010003,nStatus)

// user enters CC # into device and presses OK button. This should trigger OnCardRequestCompleteEvent



Below is the Procedure that I want the callback to trigger.

PROCEDURE GP_MyRequestCompleted(sString is UNICODE string)

WINTest_Magtek.EDT_NoName1=sString


Any ideas what I'm doing wrong?

Thanks!

von steve erts - am 31.08.2017 15:13

Re: Working with DotNetDelegate

Hi Steve,
when I compare your code to the example in the help:
clOwn is OwnEvent
clOwn:add_MyEvent(DotNetDelegate("MyHandler", "EventHandler"))
clOwn:Trigger("Hello")

I see that the dotnetdelegate object resurling from DotNetDelegate function is supposed to be registered on the .net aside (in the example, by the add_myevent method)

in your code, it seems you try to register a class (OnCardRequestCompleteEvent)) instead of the object returned by the function (CardRequestCompleted ):
clMagtek.add_onCardRequestComplete(OnCardRequestCompleteEvent)

I'm NOT a specialist in those things, but that doesn't look right

Best regards

von Fabrice Harari - am 31.08.2017 19:39

Re: Working with DotNetDelegate

Steve,

shouldn't this line
clMagtek.add_onCardRequestComplete(OnCardRequestCompleteEvent)

be as this
clMagtek.add_onCardRequestComplete(CardRequestCompleted)

So use the created object instead of an event-description (don'nt know a better word atm) ?

von Arie - am 31.08.2017 19:47

Re: Working with DotNetDelegate

Arie and Fabrice,

Bingo! that did it.

Thanks so much!

steve

von steve erts - am 31.08.2017 20:59
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.