Handling the hook function - winapi

I'm trying to use EasyHook in C# to properly hook into a method from a COM object (unmanaged).
I was able to determine the address of the method of the COM object and I can properly trigger my hook function. I did it this way, being the rest of the code pretty much similar to the one in the tutorial:
SendHook = LocalHook.Create(0x12345678, new DMyFunc(MyFunc_Hooked), this);
However, once inside my hook, all parameters are scrambled (they do not equal those that I'm originally passing).
Also, I'm not able to return anything (please note that I also tried hooking another function that returns a short and the value doesn't properly return).
When I open eXescope, this is one of the function signatures:
function MyFunc(out ParamA:^BSTR; out ParamB:^bool): ^TypeA;
And this function has the following signature when I use the COM object normally in C#:
TypeA MyFunc(ref string ParamA, ref bool ParamB);
Any ideas? Thanks in advance!

I managed to solve the problem in 5 minutes after reading the article provided by Dark Falcon. I totally recommend reading it! Therefore, all credit for the answer goes to him!

Related

Get reference to cell containing function

Is there is way to access cell that contains my UDF?
I need to reset some cache when function with same parameters is run from different cell.
Didn't find anything suitable in exceldna utils.
Thanks,
Alex
You can call
ExcelReference caller = XlCall.Excel(XlCall.xlfCaller) as ExcelReference;
The result will be an ExcelReference if you're called from a sheet formula. It might be null if you're called via Application.Run or a few other ways.
ExcelReference is a wrapper for the C API sheet reference.

c# Bot Builder SDK - Approach for Disambiguation

I'm building a LuisDialog and have LUIS integration working well.
In the cases where LUIS doesnt fill in all the gaps I need, what is the best approach for disambiguation?
Right now, I use PromptDialog callbacks - So inside a Dialog method (decorated with the LuisIntent attribute), when I need to get more details/disambiguate i'd have:
PromptDialog.Choice<string>(context, EnsureTimeOfDayChosen, new[] { "Morning (AM)", "Afternoon (PM)", "Any" }, "What time of day would you like us to book the appointment? (AM/PM/Any)", "Please choose AM or PM. Alternatively, if you don't mind which, just say Any.");
And the delegate's body (EnsureTimeOfDayChosen):
string AmPmOrAny = await result;
context.PerUserInConversationData.SetValue<string>("TimeOfDay", AmPmOrAny);
BookAppointment(context);
The problem with this approach is the last line of the delegate - it doesn't feel right. I can't easily call back into the place I was in the initially called, LuisIntent decorated method and resume.
Instead, I have to deal with the LUIS info up front, and call the BookAppointment method after gathering more info, and storing it in PerUserInConversationData.
Am I doing it wrong?
Any help would be greatly appreciated - Kind Regards,
Matt.
Given current implementation of the Dialog model, I cannot think of a better way of implementing your logic. Currently anytime that you are waiting on an async response from the user, your code will be resumed on the callback you provided upon response. You can think of it as Begin/End model for async programing

iup.GetParam in LUA: data validation in the callback function

LUA novice, experimenting with GUI using iup.GetParam using LUA 5.1.
I have a simple use of iup.GetParam (which works fine with a simple callback function testing for OK & Cancel) and am trying to add some simple data validation for the parameters (e.g. testing a parameter for being alphanumeric), but am unsure of the correct approach.
I've searched the reference manual (and for code examples), but drawn a blank so far.
Using the string validation example, if I want to reject the
character entered by the user and display the old value of the
parameter, do I simply return 0 from the callback function, or, do
I also have to reset the value of the parameter to its previous
value before the return? Or is the right approach something
completely different?
In either case, do I have to refresh / update the GUI display with a
separate iup call, or does GetParam handle that for me?
Whatever combination I try, it doesn't appear to work (the parameter happily displays the non-alphanumerics). Debugging shows the validation test and return working as coded, so the advice I'm seeking is to get confirmation of the right approach. Sharing a simple working example would be great.
simply return 0
No, IUP will do everything for you, in this case
Download the "getparam.wlua" from the examples folder, then add to its callback this:
elseif (param_index == 1) then
return 0
You will notice that the integer value is now read-only.

Webtrends Analytics implementation - Using variables in an async tracking call/pass variable as value

Does anyone here have experience doing a Webtrends implementation? According to their documentation, their asynchronous event tracking call is made by sending key-value string pairs into their tracking method, like this:
dcsMultiTrack('DCS.dcsuri', 'page.html', 'WT.ti', 'NameOfPage');
However, that model does not lend well to supporting dynamic data. What I would like to do is something like this, so that I can dynamically create the key-value pairs based on the user interaction I am capturing:
var wtString = "'DCS.dcsuri', 'page.html', 'WT.ti', 'NameOfPage'";
dcsMultiTrack(wtString);
In my proof of concept, though, that does not work. The actual webtrends JS mangles the data and the call is not made. (Sifting through their code, it looks like something breaks when assigning the arguments to the Webtrends object. Anyway, I can't edit their code because then they won't support it, so I stopped investigating that end of things.)
So the question is, how can I pass the JS variable as its value? I've done a lot of searching and tried things that I thought would both work and not work: String(), .toString(), .value(), closures, and even the dreaded eval(), but to no avail.
Any help would be MUCH appreciated. I'm at my wits end with this one.
It looks like JavaScript's apply function could help here:
var wtArguments = ['DCS.dcsuri', 'page.html', 'WT.ti', 'NameOfPage'];
dcsMultiTrack.apply(this, wtArguments);
This is effectively the same as calling:
dcsMultiTrack('DCS.dcsuri', 'page.html', 'WT.ti', 'NameOfPage');

How to create dynamic Callbacks in MATLAB?

I have this line of code:
delete_btn = uicontrol(rr_ops, 'Style', 'pushbutton', 'String', 'Delete Graphic', 'Position', [13 135 98 20], ...
'Callback', 'delete_graphic');
and a little bit upper this function:
function delete_graphic
global rr_list
selected = get(rr_list, 'Value');
selected
return;
why this code is not working? I really dont understand...
What do I need? I create one button and a listbox, clicking on button - deleting selected element from a listbox.
Thx for help.
PS
Always getting this error:
??? Undefined function or variable 'delete_graphic'.
??? Error while evaluating uicontrol Callback
here is all my code: http://paste.ubuntu.com/540094/ (line 185)
The generally-preferred way to define a callback function is to use a function handle instead of a string. When you use a string, the code in the string is evaluated in the base workspace. This means that all the variables and functions used in the string have to exist in the base workspace when the callback is evaluated. This makes for a poor GUI design, since you don't really want the operation of your GUI dependent on the base workspace (which the user can modify easily, thus potentially breaking your GUI).
This also explains the error you are getting. The function delete_graphic is defined as a subfunction in your file rr_intervals.m. Subfunctions can only be called by other functions defined in the same m-file, so delete_graphic is not visible in the base workspace (where your string callback is evaluated). Using a function handle callback is a better alternative. Here's how you would do it:
Change the callback of your button (line 216) from 'delete_graphic' to #delete_graphic.
Change the function definition of delete_graphic (line 185) to:
function delete_graphic(hObject,eventdata)
where hObject is the handle of the object issuing the callback and eventdata is optional data provided when the callback is issued.
EDIT:
If you want to pass other arguments to delete_graphic, you can perform the following steps:
Add the additional input arguments to the end of the function definition. For example:
function delete_graphic(hObject,eventdata,argA,argB)
Use a cell array when you set the callback for your button, where the first cell contains the function handle and the subsequent cells each contain an input argument. For example:
set(delete_btn,'Callback',{#delete_graphic,A,B});
There is one caveat to this, which is that the values A and B stored in the cell array are fixed at what they are when you set the callback. If you change A or B in your code it will not change the values stored in the cell-array callback.
If you aren't able to use the above solution (i.e. if A and B need to change value), there are a few other options for how you can share data among a GUI's callbacks:
You can rework the organization of your code to make use of nested functions. This makes it very easy to share data between callbacks. Some nice examples of using nested functions to create GUIs can be found in the MathWorks File Exchange submission GUI Examples using Nested Functions by Steven Lord.
You can store data in the UserData property of a uicontrol object. To access or update it, you just need the object handle.
You can use the functions SETAPPDATA/GETAPPDATA to attach data to a handle graphics object (i.e. uicontrol).
Since it appears your code was created using GUIDE, you can make use of the handles structure GUIDE creates to store data using the GUIDATA function.

Resources