I need to make some relatively simple calls to objc_msgSend on OS X from C. This code use to work id event_data = objc_msgSend((id) objc_getClass("NSEvent"), sel_registerName("eventWithCGEvent:"), event_ref);, however, Apple recently changed the function signature to void objc_msgSend(void); to address some issues. The general consensus is that this should be solved with a function pointer, however, I am unable to get this to work without some ominous warnings about "function called through a non-compatible type" and "if this code is reached, the program will abort." My new function pointer implementation looks like id event_data = ((id (*)(id, SEL, CGEventRef)) objc_msgSend)((id) objc_getClass("NSEvent"), sel_registerName("eventWithCGEvent:"), event_ref); but I am concerned about the warnings. The event_ref variable is a function parameter defined as CGEventRef event_ref. Does anyone have an idea for making this work?
How to call objc_msgSend from C on modern OS X versions
235 views Asked by Alex Barker At
1
There are 1 answers
Related Questions in C
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in MACOS
- Error installing Nativescript on Mac M2 Sonoma 14.4.1
- macOS - Most secure way of a GUI SUDO_ASKPASS
- When using onDrag in SwiftUI on Mac how can I detect when the dragged object has been released anywhere?
- Why does Hugo generate different taxonomy-related HTML on different OS's?
- ZSH function parameters conundrum
- how to make read only file/directory in Mac writable
- macOS BigSur - Unable to run bundled php version or brew php 8
- 9 Digit Addresses in Hexadecimal System in MacOS
- MacOS Bash-Script: while read p and echo
- How to make a range for tail rows on a categorized table in Numbers with JXA scripts?
- Cannot build a basic project with curl on Mac (M2) for Raspberry Pi Pico
- How to recover deleted files from create vite react project
- Can't run built SFML project from Xcode template
- React Native - RealmJS - Linker command failed with exit code 1
- How can I manually add a keyboard shortcut to a Shortcut Action Service directly via the system files, without going through the System Prefs GUI?
Related Questions in FUNCTION-POINTERS
- Constant function pointer optimization
- Function pointer initialized at NULL but evaluated at 0xffffffff
- How to pass a C++ function into a C one that takes function pointer with unspecified parameter?
- Meaning of constant function pointer
- Why does `function == &function`?
- C++ Callback to member function pointers on ESP32 / Arduino
- Function notation for function pointer parameters in ISO C Standard
- How to map function pointer argument of a function in a subsubsection of Doxygen?
- C-style wrapper to C++ functor
- Why Function pointer is used in Call back function any other usecase?
- How can i call a dyn function stored within a Box?
- How to pass callback + context to C function from Go using cgo
- Is it safe to cast a function pointer accepting pointer type to another function pointer accepting reference type?
- Variadic function pointer in C
- ANTLR4 for Function Pointers in C
Related Questions in LIBOBJC
- Programmatically focus on a form in a webview (WKWebView) in xamarin ios 13 and above
- libobjc: Calling a ObjC method from plain C?
- How to call objc_msgSend from C on modern OS X versions
- libobjc.A.dylib crashed? How can I debug?
- iOS crash libobjc.A.dylib objc_msgSend
- Why is this inline assembly calling release, retain, and autorelease in libobjc?
- Valgrind showing leaked memory with libobjc
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
You could try:
This defines a function pointer called
eventWithCGEventwith three parameters: a receiver (since it is a class method, it is of typeClass), the selector, and a parameter of typeCGEventRef.In a little more context it could look something like this: