Which Smalltalk object should be passed to a C function expecting const char*

倖福魔咒の 提交于 2021-01-27 14:36:02

问题


I want to call the following C function:
int ssh_userauth_password (ssh_session session, const char * username, const char * password)

But regular Smalltalk strings are not working:
library ssh_login: session userAuth: nil password: 'myPwd'.

session is a pointer that i already have and works ok.
But const char * are not mapped to normal string. Is there any class to map this ? Also i tried with CPointer and asByteArray but both fail.


回答1:


You need to pass a CPointer object. Easiest way to do that is via 'yay' gcCopyCStringToHeap. Alternatively there‘re variations like gcCopyUnicodeStringToHeap.



来源:https://stackoverflow.com/questions/62800888/which-smalltalk-object-should-be-passed-to-a-c-function-expecting-const-char

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!