D
Deno

help

What should I specify to pass a "char *" in Deno.dlopen?

8/7/2023
For example, this is how you would use it in Python:
import ctypes

lib = ctypes.cdll.LoadLibrary('example.dll')
check = lib.check
check.argtypes = [ctypes.c_char_p]
check.restype = ctypes.c_char_p
import ctypes

lib = ctypes.cdll.LoadLibrary('example.dll')
check = lib.check
check.argtypes = [ctypes.c_char_p]
check.restype = ctypes.c_char_p
8/7/2023
https://deno.land/manual@v1.36.0/runtime/ffi_api#supported-types I looked here but couldn't find the appropriate type Not familiar with native code
Deno
Foreign Function Interface | Manual | Deno
As of Deno 1.13 and later, the FFI (foreign function interface) API allows users to call libraries written in native languages that support the C ABIs (C/C++, Rust, Zig, V, etc.) using Deno.dlopen.
NNeTT8/7/2023
buffer should do if it is from the JS side pointer if from Native side check out denonomicon https://denonomicon.deno.dev/types (tho the styles are broken atm)
8/7/2023
Using buffer gets a funny response. [Object: null prototype] {} So pointer is probably the correct answer. Learn about the pointer. Given pointer, it asks for Deno.PointerValue as its argument, so it tries to find a way to convert the string to Deno.PointerValue. Thank you!
NNeTT8/7/2023
are you passing a char * to the native code? or are you sending it from native code to JS?
8/7/2023
I send it to a Go program compiled from Deno to dll.
func check(ExampleArg *C.char) *C.char {
// do anything
return C.CString('a')
}
func check(ExampleArg *C.char) *C.char {
// do anything
return C.CString('a')
}
NNeTT8/7/2023
ah idk how it is done generally but I can provide an example of how I do it I convert my text into a Uint8Array with a TextEncoder and pass it as a buffer type the native code can parse the byte stream as a string or whatever I also pass an additional Uint8Array to which the native code writes the response and I parse it in the JS side after the FFI call
8/7/2023
const library = Deno.dlopen('example.dll', {
check: {
parameters: ['buffer'],
result: 'buffer',
nonblocking: true,
},
});

const response = await library.symbols.check(new TextEncoder().encode('a'));
console.log(response);
const library = Deno.dlopen('example.dll', {
check: {
parameters: ['buffer'],
result: 'buffer',
nonblocking: true,
},
});

const response = await library.symbols.check(new TextEncoder().encode('a'));
console.log(response);
[Object: null prototype] {} The console displays the above results I thought there was a problem with the dll, but I suspect there is a problem with my code because I called it from Python and it successfully asked for a response Sorry [Object: null prototype] {} I looked at it and decided it wasn't the right response, but when I correctly parsed the results, it worked. I mistakenly thought that an empty object was being returned. Thank you 😢
NNeTT8/7/2023
<:hooray_deno:1035517542200004688> result: 'buffer' doesn't do anything different from pointer as parameter types, they are different but as return types, they are the same
8/7/2023
I see, I learn a lot! Thank you so much😭
NNeTT8/7/2023
<:cookie_deno:1002977285734932480>

Looking for more? Join the community!

Recommended Posts
Override NPM package dependencyRelating to my question yesterday (https://canary.discord.com/channels/684898665143206084/1137532072VS Code's debugger terminates before finishedI notice that occasionally the debugger terminates at the middle of the running, or at least doesn'tI need some guidance regarding interprocess communication with DenoWhat are good cross-platform (Windows, Linux) options for interprocess communication / data sharing What is the Deno class?What is Deno in Deno.cwd() ? Can someone link me to documentation? Why doesn't the Deno class need tGetIP + Ctx from middleware to a route not passedHi, I have test to retrieve IP visitor Code taken from Discord is always returning "localhost" (wheerror: No config file found in VS CodeI'm new in Deno and in coding, and need help with the following issue. I have installed Deno throughDeclaration merging for external packagesHi! I'm using unoCSS with Deno Fresh and have been attempting to use the attributify preset (https:Deno.serve AbortController onError. How?When I run my new Deno.serve() updated implementation I get a type error. Perhaps I'm doing it wrongLocalStorage OverrideI'm using a library (@supabase/supabase-js), and I'm compiling my Deno app into an executable, howevBad implementation of X25519?I can't generate a shared secret with the current implementation of X25519 ```ts const alice = awaiResize image/convert on uploadHi there, I want to store images uploaded in webp format at 200x200px. Has anyone done something likI cant import the Zustand module from deno.I leave a photo of what it shows when I put the url to the import map. And try to cache the module.Sub hosting SAAS appWhat technologies are behind the Deno Deploy feature, where you can set up your own domain name? I What should my entry point be on Deno Deploy?Only ever used firebase before. I'm getting a 502 bad gateway error when deploying my website.tsParticles & DenoHi, I’m working on a personal project with Deno & Lume. I’m trying to use tsParticles with preact. Looking for a library to pretty print </br>, <a>, etc tagsAs that title says, I'm looking for a library that can pretty print a string containing the mentioneImporting `puppeteer-cluster` from esm.sh causes `does not provide an export named 'default'` errorWhen importing `https://esm.sh/puppeteer-cluster@0.23.0` I get the following error: ``` error: UncauDeno linting not workingHello everyone, I enabled deno for a subpath in my project (`./supabase`) but unfortunately I'm not deno_pythonI'm trying to use Python with Deno with https://deno.land/x/python@0.2.7 What should I do to enable Deno VS Code plugin too aggressive in auto-completionI'm new to Deno and learning through some tutorials. I'm using VS Code and have the Deno plugin enab