How to host licensed .Net controls in unmanaged C++ app? - c++

I need to host and run managed controls inside of a purely unmanaged C++ app. How to do this?
To run unlicensed controls is typically simple:
if (SUCCEEDED(ClrCreateManagedInstance(type, iid, &obj)))
{
// do something with obj
}
When using a licensed control however, we need to somehow embed a .licx file into the project (ref application licensing). In an unmanaged C++ app, the requisite glue does not seem to work. The lc.exe tool is supposed to be able to embed the license as an assembly resource but either we were not waving the correct invocation, or it failed silently. Any help would be appreciated.

The answer depends on the particular component you're using. Contact your component help desk OR read up the documentation on what it takes to deploy their component.
Basically component developers are free to implement licensing as they deem fit. With the .licx file the component needs to be able to do whatever the developer wished via GetKey and IsValidKey (explained in the link you posted).
So if GetKey checks for a .licx file in the component directory - you just need to make sure its there.
AFAIK the client assembly doesn't need to do anything except instantiate the control.
Also if you post the name of the component and the lc.exe command you're using, people could take a look..

Related

How do I change the Unreal Engine AppleARKitLiveLink Settings via user input?

After compiling the Unreal Engine FaceARSample project the user can send the iPhone's facial blendshape data via the AppleARKitLiveLink plugin to a computer on their network with an IP address they define. I want to change it so the user can edit other LiveLink settings as well. Most importantly, the Subject Name.
So I found in the FaceARSample where the LiveLink source is created, inside of AppleARKitFaceSupportlmpl.cpp. The console command "LiveLinkFaceAR SendTo= [IP Address] " is used to change where LiveLink is publishing to. Upon pressing a button in the compiled app this console command is triggered which uses the line of code below to send the data over the network:
RemoteLiveLinkPublisher = FAppleARKitLiveLinkSourceFactory::CreateLiveLinkRemotePublisher(RemoteIp);
I've tried to make my own AppleARKitLiveLinkSourceFactory through blueprints but I couldn't figure it out. I found that I could edit the default subject name in the AppleARKit Project Settings. Is it possible to give the user access to these project settings via blueprints?
I'm confused about where to start. I've taken a look at the Maya LiveLink plugin, read the Unreal Engine documentation,and studied C++ for about 4 weeks now but I'm still confused. Do I need to somehow create an Unreal Engine module and #include the AppleARKit plugin then derive my own class from the AppleARKitLiveLinkSourceFactory? Do I need to create my own AppleARKit plugin from scratch?
Here's the documentation I read:
https://docs.unrealengine.com/en-US/Engine/Animation/LiveLinkPlugin/LiveLinkPluginDevelopment/index.html
You need to create your own plugin or game code, there you need to include the AppleARKit module editing your Build.cs then you can use their exported classes.
By instance all settings you can see in the project settings are driven by static UObjects, you can access all them if they are expose using something like this:
class* myclass = GetMutableDefault<>();
In this case you want to look for UAppleARkitSettings, now that been said, looks like that variable is protected, so you will not be able to modify it at all. if you really want to modify it through custom nodes in blueprints, you have 2 options, if you have the source, just change it to public, second option is remove the plugin from your engine, and paste it in your per project plugin folder and edit it there.
that's the closest you can go, nevertheless I suggest you changing that from the settings, looking to the architecture I can't see a valid reason to change that via BP, but it is up to you
Cheers and hope that helps

Can I have a COM interface in a service to be called from Windows Script Host?

My goal is to create a COM interface in my Windows local service, written with C++/MFC, whose methods could be called from a Windows Script Host JScript code running under a logged in interactive user account.
For instance, if I have a test.js that can be started with credentials of a logged in user, that does the following:
var Obj = new ActiveXObject("myservice.somename");
var Result = Obj.MyMethod("some data");
and then have MyMethod function processed in my service & return a value.
I know it's a general concept. At this stage I'm curious if such is possible (from a Windows security stand-point, i.e. calling system service from a user process) and if so, if there's any sample code that I can use as a basis for this?
I'm assuming that it must be some COM interface, right? But usually those go into a DLL. I've never tried to put them in a service.
Thank you!
I'm posting it for my own future reference, in despite of the treatment I got in the comments to my original post. It would've saved me a day of search if someone pointed me to this article...
This CodeGuru article, "COM in plain C, Part 2" explains how to create a COM interface that can be called from the Windows Script Host. His IExample2 project shows how to create an in-proc DLL that hosts the COM interface that can be called from a VBScript included in the same project. Then regiexample2 and unregiexample2 projects also show how to register/unregister the COM interface. The VBScript can be easily adjusted to work with JScript in my OP.
One word of caution though, that project is intended to be used for installation on a 32-bit OS. For 64-bit OS, you will need to build and register a 64-bit version of the in-proc COM Dll. The registration part from a 32-bit process is similar to the one shown, except that one needs to include the KEY_WOW64_64KEY flag when opening/creating registry keys.

Ways to communicate between JScript and Windows service

I have a Windows local service that may spawn off a process to execute a JScript script (in a .js file) via the Windows Script Host. The issue is that I need to notify my service of the results generated by the script in the .js file. A transfer or a simple 32-bit integer, or a string would suffice. What would be the way to do this?
PS. The code must run on Windows XP SP3 or later OS.
Your best bet is to create an out of process COM object that executes within your service. Just implement the necessary scripting interfaces and provide a member function to match the notification and call it from your script as such:
newObj = new ActiveXObject("localserver.mynotify");
newObj.Notify("finished");
Would the exit code of the process be enough?
Windows Scripting host has has a .Quit(errorCode) method that allows you to set the exit code.
You should be able to call WSH directly from the service and get the return code with GetProcessExitCode() by passing the process handle that you received after spawning it.
Note that almost everything you can do from a JScript file can also be done with native code.
Do you have to execute the .js file as an external process? Windows Scripting has COM objects that an app can use to run scripts within its own process. I use this to execute script files within my service processes, and it works fine. The hosting process can even implement its own IDispatch-based classes and pass them to the scripting engine to expose to scripts as global objects so the scripts can communicate with the hosting process without having to use new ActiveXObject or CreateObject() to access those objects.
I see your script is written in JScript and your app in C++.
Perhaps the easiest way to accomplish what you want is by writing a file, say, to programdata folder which your service should have access to. Maybe use a GUID for the particular request, pass that to the JScript so it's guaranteed to be a unique file. Not ideal.
Another way to get JScript output ... Can you call out to managed code (C#)? If so, you could use a .NET-based or .NET-callable JavaScript compiler/interpreter. This would allow you to avoid IActiveScript and also to grab the values right out of the script context or from function return. I've used Jurassic and JavaScriptDotNet, both very easy to use and extend.
This might open a problem if you heavily rely on ActiveXObject calls (ie: FileSystemObject) and don't want to write components. JuraScript wraps the Jurassic engine and add ActiveXObject support to it for COM automation.
I am a C++ newb, so I don't know how much of a leap this is for you although I know it's possible to interop between managed/C++.
Just thought I'd mention these scenarios as I didn't see them listed in answers.

Inject C code into *nix application: replacing a function

I have a newbie but really important question for me: I have a Mac Os X application that uses carbon api, but it is still a C++ application. I need to debug which functions are called at execution time and then make a C++ patch to replace one of those functions.
The real goal: I need to log all text printed into a chat window that the application has inside an unnacessible carbon view. I thought at first it was a cocoa application, but it's not, so fscript and imlib are no good to inject code.
Is it possible? Any clues? Thank you very much.
Cheers :)
You could look into using truss to figure out what system calls are being made but I'm not sure for user-calls. The LD_PRELOAD environment variable can allow you to inject methods into other apps, but C++ methods tend to have various dependencies regarding name mangling and calling method so it would probably be tricky to plug in your own.
Can you just have the app maintainer add actual hooks to allow for what you need?

IE ActiveX plugin cannot create file

I wrote an IE plugin using MFC activex. The plugin actually creates a file in CLSID_APPDATA folder and writes some data inside it. But the problem is that file which is created cannot be seen (i mean i cant see any file in CLSID_APPDATA folder on windows vista) whereas I am actually writing data inside it. The plugin is not signed.
I have the code from http://support.microsoft.com/kb/161873 to mark my activex component as safe.
Please let me know if I need to do something more to make it possible for file creation. I hope I was clear. Do let me know if I need to provide more details.
regards,
Pradip.B
It sounds like you're falling foul of IE's "Protected Mode" which redirects file writes made from IE from \Users\UserName\Local\ to \Users\Username\LocalLow (or something very similar to that).
Take a look at the following links as they should point you in the right direction:
More details on Protected Mode IE in Windows Vista
The difference between Local and LocalLow folders