Raised This Month: $32 Target: $400
 8% 

How to pass a MenuHandler through Natives?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BRU7US
Member
Join Date: Jul 2020
Location: Tatarstan, Kazan
Old 03-11-2023 , 07:49   How to pass a MenuHandler through Natives?
Reply With Quote #1

As far as I know i can pass a MenuHandler address through GetNativeFunction(). But when i'm trying to compile plugin i get an error like "error 100: function prototypes do not match".

Code:
PHP Code:
public any Native_Create_CustomPanel(Handle pluginint numParams)
{
    
char panelTitle[32];
    
GetNativeString(3panelTitlesizeof(panelTitle));

    
MenuHandler menuHandler GetNativeFunction(2);

    
Create_CustomPanel(GetNativeCell(1), menuHandlerpanelTitleGetNativeCell(4), GetNativeCell(5));
    return 
0;

BRU7US is offline
bayshades
Member
Join Date: Sep 2019
Old 03-17-2023 , 10:19   Re: How to pass a MenuHandler through Natives?
Reply With Quote #2

It looks like the error message you are getting indicates that the function prototype for the MenuHandler parameter does not match what is expected by the GetNativeFunction() call. Without knowing the exact details of your code, it's difficult to say exactly what the issue is.

However, one thing to keep in mind is that when passing a function pointer through a native, the signature of the function pointer must match the expected signature defined by the native. In other words, the native expects a specific type of function pointer with a specific number and type of arguments.

Make sure that the MenuHandler type matches the expected function pointer type defined by the native you are calling. If the types don't match, you may need to use a type cast to convert the function pointer to the correct type before passing it to the native.

Additionally, double-check that you are passing the correct number and types of arguments to the native. If any of the arguments are incorrect, you may get a similar error message.
bayshades is offline
BRU7US
Member
Join Date: Jul 2020
Location: Tatarstan, Kazan
Old 03-17-2023 , 16:17   Re: How to pass a MenuHandler through Natives?
Reply With Quote #3

Quote:
Originally Posted by bayshades View Post
It looks like the error message you are getting indicates that the function prototype for the MenuHandler parameter does not match what is expected by the GetNativeFunction() call. Without knowing the exact details of your code, it's difficult to say exactly what the issue is.

However, one thing to keep in mind is that when passing a function pointer through a native, the signature of the function pointer must match the expected signature defined by the native. In other words, the native expects a specific type of function pointer with a specific number and type of arguments.

Make sure that the MenuHandler type matches the expected function pointer type defined by the native you are calling. If the types don't match, you may need to use a type cast to convert the function pointer to the correct type before passing it to the native.

Additionally, double-check that you are passing the correct number and types of arguments to the native. If any of the arguments are incorrect, you may get a similar error message.
Thank you for your reply. A little later, I'll write more code, where and what is called and write about why I did it this way and what errors occur during the operation of plugins, which exchange via Native pointers to MenuHandler
BRU7US is offline
reBane
Senior Member
Join Date: May 2020
Old 03-18-2023 , 08:53   Re: How to pass a MenuHandler through Natives?
Reply With Quote #4

In the inlcude I just used a MenuHandler argument

And in my native code i just used view_as<MenuHandler>(GetNativeFunction(n))

You can then call the function using Call_StartFunction

The lines above are linked to respective examples in my MotdMenu plugin (proxying the MenuHandler was required for players that have motds disabled and get a regular VGUI menu)
__________________
Plugins & LibrariesListingGitHubDosMikeTools ▶ ToDo
reBane is offline
BRU7US
Member
Join Date: Jul 2020
Location: Tatarstan, Kazan
Old 03-19-2023 , 07:46   Re: How to pass a MenuHandler through Natives?
Reply With Quote #5

Quote:
Originally Posted by reBane View Post
In the inlcude I just used a MenuHandler argument

And in my native code i just used view_as<MenuHandler>(GetNativeFunction(n))

You can then call the function using Call_StartFunction

The lines above are linked to respective examples in my MotdMenu plugin (proxying the MenuHandler was required for players that have motds disabled and get a regular VGUI menu)
Thanks a lot, I will try to implement your method.
BRU7US is offline
BRU7US
Member
Join Date: Jul 2020
Location: Tatarstan, Kazan
Old 03-19-2023 , 09:33   Re: How to pass a MenuHandler through Natives?
Reply With Quote #6

Quote:
Originally Posted by reBane View Post
In the inlcude I just used a MenuHandler argument

And in my native code i just used view_as<MenuHandler>(GetNativeFunction(n))

You can then call the function using Call_StartFunction

The lines above are linked to respective examples in my MotdMenu plugin (proxying the MenuHandler was required for players that have motds disabled and get a regular VGUI menu)
Seems like This method isn't working on SM 1.11. After trying of compilation i got compilation error on this string: "error 100: function prototypes do not match"

My Native implementation:
PHP Code:
native void PanelManager_Create_CustomPanel(int clientMenuHandler panelHandlerMenuAction actions MENU_ACTIONS_DEFAULTchar[] panelTitleHandle buttonsTitleArrayHandle footerStringsArray); 
BRU7US is offline
reBane
Senior Member
Join Date: May 2020
Old 03-19-2023 , 10:42   Re: How to pass a MenuHandler through Natives?
Reply With Quote #7

Sorry, based on this PR and this Issue you're not supposed to use view_as on functions anymore. It should work, if you just use the type Function
__________________
Plugins & LibrariesListingGitHubDosMikeTools ▶ ToDo
reBane is offline
BRU7US
Member
Join Date: Jul 2020
Location: Tatarstan, Kazan
Old 03-22-2023 , 11:34   Re: How to pass a MenuHandler through Natives?
Reply With Quote #8

Thanks! But how can i pass this MenuHandler by Function?
BRU7US is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:43.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode