I'm new to Visual Foxpro. I want to build a dynamic link library (dll) file using Visual Foxpro for calling the Visual Foxpro function in Node or Java to build rest API.
I tried it with Node and Java. I had an issue when I used the Foxpro dll file. So I created a C# dll, and got the same issue. So then I read a document which said to use > [DLLEXPORT] tag above the function which I want to call in another native language.
I built a 32-bit and 64-bit dll to use with my native language code. It was successful. My question is that I want to build both 32-bit and 64-bit dll files with Visual Foxpro to use with Node.js code.
This is my C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using net.r_eg.DllExport;
namespace FDLL
{
public class First
{
[DllExport]
public static String getData()
{
Console.Write("Call Function Successfully!");
return "HI Welcome";
}
}
[DllExport]
public static String getData1(String a)
{
Console.Write("Call Function Successfully!");
return "HI Welcome"+ a;
}
}
If I did not use [DllExport] tag, getData could not be invoked in my Node or java code.
This is my Node.js code:
const ffi = require("#saleae/ffi");
const libm = ffi.Library("./FDLL", {
getData: ["string", []],
getData1: ["string", ["string"]]
});
It works fine, but my Foxpro dll is not working.
This is my Visual Foxpro code:
This is the JavaScript code for accessing my Foxpro GetDrugsJSON() function
var libm1 = ffi.Library("./cw/comdemo", {
GetDrugsJSON: ["String", []],
});
console.log(libm1.GetDrugsJSON())
But I cannot invoke GetDrugsJSON() function with JavaScript code.
How do I fix this issue?
Long story short, you cannot build 32 and 64 bits DLL with VFP.
Also a DLL is a broad term (while it is short for Dynamic Link Library, there are different DLLs).
You are saying "in Node or Java to build rest API". For creating REST API you wouldn't want to use VFP. Use something else, be it C#, Go, ...
With other languages too, if you are accessing VFP data via VFPOLEDB then it needs to be 32 bits.
Related
I am using JS package for Flutter to JS communication and vice versa.
It's working fine when I try to run on the web but giving errors when trying to run in the mobile emulator.
I am trying this
import 'package:flutter/material.dart'
if(dart.library.jqyery) 'common.dart';
But that starts giving errors on all the functions which are in file common. dart
This is common. dart
#JS()
library jquery;
import 'globals.dart';
import 'package:js/js.dart';
#JS('myCallDartToJSFunction')
external void myAlert(String str);
#JS('connectToSignalR')
external void connectToSignalR();
#JS("mySendMsgTSignalR")
external void myDartSendMsgTSignalR(String nam, String msg);
#JS('myCallJSToDart')
external set _myCallJSToDart(void Function(String str, int x) f);
#JS()
external void myCallJSToDart(String str, int x);
void _someDartFunction(String str, int x) {
print(str + x.toString());
msgFromSignalr = str;
}
#JS('messageFromSignalR')
external set _messageFromSignalR(void Function(String str) f);
#JS()
external void messageFromSignalR();
String _dartmessageFromSignalR(String str) {
}
void bindmain() {
_myCallJSToDart = allowInterop((text, x) => _someDartFunction(text, x));
_messageFromSignalR = allowInterop((str) => _dartmessageFromSignalR(str));
}
In your example you are importing flutter/material.dart when you are on mobile which won't be accepted as a valid replacement for common.dart. When doing conditionnal imports you should always provide 2 identical implementations. In your case it means making a file, for example, common_mobile.dart which will implement the same methods that are in your common.dart but doing nothing (or even throwing an UnimplementedException) as they should not be called while you are on mobile.
I see that you are making a library inside your common.dart which is not recommended if you want to keep both a mobile and a web implementation as you would have 2 library with the same name.
A conditionnal import should be done as follow:
import 'common_mobile.dart'
if (dart.library.js) 'common.dart' as commonUtils;
In this sample I am importing by default the file common_mobile.dart but if I am on the web version (which can be verified with if (dart.library.js)) I am importing common.dart. I am adding the as commonUtils keyword to secure my calls to my import.
Now to make a call myAlert for example:
/// Making a web verification to ensure your call is only done when running on web.
if (kIsWeb) {
/// It should call the myAlert implementation from common.dart
commonUtils.myAlert('Test');
}
Moreover I am seeing that your package does not support mobile which means that if there is build errors related to your package directly you won't be able to build on mobile no matter what you do and your only option is to separate your project into 2 branches (one mobile only and the other one web only) to remove packages that only supports only a specific platform.
I am currently developing an application in php / js / html and I would like to launch an application made in C # via a html button (no download) however I use Mozilla Firefox and the only solution I found is a script featuring ActiveXObject which is only used by IE apparently.
You can use the Firefox command line options of -url
"C:\Program Files\Mozilla Firefox\firefox.exe" -url "https:\\www.stackoverflow.com"
or
Use selenium Webdriver, this can launch the browser to any url you specify and can fill any form on the page with any details you specify and press any buttons that you can find.
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
using SeleniumExtras.WaitHelpers;
class HelloSelenium
{
static void Main()
{
using (IWebDriver driver = new FirefoxDriver())
{
WebDriverWait wait = new WebDriverWait(driver);
driver.Navigate().GoToUrl("https://www.stackoverflow.com/ncr");
driver.FindElement(By.Name("q")).SendKeys("Vote Up" + Keys.Enter);
}
}
}
I am a iOS Developer, am new to javascript.
I wants to create a communication between Javascript to Objective C and Objective C to Javascript.
How to pass a variable from javascript to objective C and Objective C to Javasctipt in ios.
If any one have references please let us know about this?
I program JavaScript when using Parse CloudCode. In my case, I use CloudCode to call the Stripe API.
For example:
Objective-C
NSDictionary *parameters = #{
#"customerId": stripeCustomerId,
#"amount": #(100),
};
[PFCloud callFunctionInBackground:#"chargeCustomer" withParameters:parameters block:block];
JavaScript
Parse.Cloud.define("chargeCustomer", function(request, response) {
Stripe.Charges.create({
amount: request.params.amount, // in cents
currency: "usd",
customer: request.params.customerId,
},{
success: function (httpResponse) {
console.log(httpResponse);
response.success(httpResponse);
},
error: function (httpResponse) {
console.error(httpResponse.message);
response.error(httpResponse.message);
}
});
});
As you can see, to pass on the variable from objective-c to javascript in this case, you use request.params.
If you are targeting iOS8, you could consider to use WKWebView rather than UIWebView, which has considerably improved in this regard. Good starting points are the the WKWebView reference docs and this NSHipster article.
You can use native iOS objects to do this.
From Obj-C to JS
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
It injects or calls pre-existing method/object in the page loaded in the UIWebview. It returns the value that JS return to you
UIWebView Class Reference
From JS to Obj-C
Implementing UIWebView protocol you can handle the request before it will start:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest (NSURLRequest *)request navigationType (UIWebViewNavigationType)navigationType
So, from JS you have to call a URL with a custom schema http such as test://. Then you will parse the request in the delegate method I wrote before.
This situation: Like PhoneGap, I want to define and call an inexistent JavaScript function, which need to access ios features. e.g.,
javascript code:
function onClickButton(){
toModule(true, true, "title1", 1);
}
I want to access iOS features through the function toModule. But How? Can you tell me?
PS: I know one solution JS->iOS is by using UIWebViewDelegate's
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
but I don't want that solution, just handle the JS function toModule(...)
From javascript(phonegap) you cant access ios native code directly instead you should use or develop a phonegap plugin that could establish this connection .
you can find more at Plugin Development Guide
This is very Simple
Step 1) Include cordova.js file in your project
Step2) Include cordova.js in your javascript file and in your javascript file add the following code
cordova.exec(
function successCallback() {
},
function errorHandler(err) {
},
'Login', 'callLogin', [param]);
}
here Login is the name of native class and callLogin is function in Login class, param is the array of parameters you want to send to native file
Step3) Goto config.xml and this
<feature name="Login">
<param name="ios-package" value="Login"/>
</feature>
Step4)
- (void)Login:(CDVInvokedUrlCommand*)command
{ // this is the native function, which is being called from javascript file, do your work here
}
Step5) If you want to send any data back to js file from native you need to write the below code.
NSString * jsCallBack = [NSString stringWithFormat:#"callJsFunction(parameters)];
[self.webView stringByEvaluatingJavaScriptFromString:jsCallBack];
callJsFunction() is the name of the js function which you want to call from native.(you can send string only)
Step6) To fetch value from native to js you need to write callJsFunction(parameters) in js file. write below function in js file
callJsFunction(parameters)
{
}
this is the complete process for calling native function from js and js from native class.
Given the rise of Javascript in Windows 8, does Windows 8 / .Net 4.5 / VS 2012 provide a mechanism to embed the Chakra javascript engine in application to enable scripting? If so, is there documentation for this somewhere?
There is no mechanism to do this that has been released or talked about. For now, it is available only in IE and to Metro style apps. There isn't even a Windows Scripting Host style exposure of it.
What is it about Chakra that you want in your scripting?
Doesn't IE ActiveX use the same JavaScript engine as IE standalone?
You can simply embed Internet Explorer ActiveX frame and keep it hidden.
Yes, exists.
See: https://github.com/Microsoft/ChakraCore/wiki/Embedding-ChakraCore
using System;
using System.Runtime.InteropServices;
using ChakraHost.Hosting;
public class HelloWorld
{
static void Main() {
JavaScriptRuntime runtime;
JavaScriptContext context;
JavaScriptSourceContext currentSourceContext = JavaScriptSourceContext.FromIntPtr(IntPtr.Zero);
JavaScriptValue result;
// Your script, try replace the basic hello world with something else
string script = "(()=>{return \'Hello world!\';})()";
// Create a runtime.
Native.JsCreateRuntime(JavaScriptRuntimeAttributes.None, null, out runtime);
// Create an execution context.
Native.JsCreateContext(runtime, out context);
// Now set the execution context as being the current one on this thread.
Native.JsSetCurrentContext(context);
// Run the script.
Native.JsRunScript(script, currentSourceContext++, "", out result);
// Convert your script result to String in JavaScript; redundant if your script returns a String
JavaScriptValue resultJSString;
Native.JsConvertValueToString(result, out resultJSString);
// Project script result in JS back to C#.
IntPtr resultPtr;
UIntPtr stringLength;
Native.JsStringToPointer(resultJSString, out resultPtr, out stringLength);
string resultString = Marshal.PtrToStringUni(resultPtr);
Console.WriteLine(resultString);
Console.ReadLine();
// Dispose runtime
Native.JsSetCurrentContext(JavaScriptContext.Invalid);
Native.JsDisposeRuntime(runtime);
}
}