Which library contains pulseaudio pa_simple_new function - java-native-interface

I am writing a java application. It is an mp3 player. I want to use the pulseaudio server because my bluetooth speaker is accessible with pulseaudio.
I have written a shared library using the simple pulseaudio interface.
Now i get the error
/home/rainer/NetBeansProjects/audioserver/src/main/native/audioserver.so: undefined symbol: pa_simple_new
which library i have to add to my java program to get access to the symbol pa_simple_new ?

After searching around, i found the library libpulse-simple.so contains the functions. There were shown when executing
nm -D libpulse-simple.so
I wasn't able to call the functions directly, because i call this functions in a JNI environment.
I had to use the functions dlopen and dlsym for accessing the functions:
void* h = dlopen("libpulse-simple.so", RTLD_LAZY|RTLD_GLOBAL);
and
ptr_pa_simple_new = (pa_simple* (*)(const char *,const char *,pa_stream_direction_t,const char *,const char *,const pa_sample_spec *,const pa_channel_map *,const pa_buffer_attr *,int *))dlsym(h,"pa_simple_new");
ptr_pa_simple_free = (void (*)(pa_simple *))dlsym(h,"pa_simple_free");
ptr_pa_simple_write = (int (*)(pa_simple *, const void *, size_t, int *))dlsym(h,"pa_simple_write");

Related

How can i create serviŅe?

So, i want create service. My program need work as service, but not process. I finded in Internet and edited this code :
#define rootkitname "myrootkit"
SC_HANDLE hSCManager;
hSCManager=OpenSCManager(NULL, NULL,SC_MANAGER_CREATE_SERVICE);
LPVTSTR rootkpath;
rootkpath="C:\Users\Admin\Desktop\Blocker\Project1.exe";
SC_HANDLE hManager,hService; hService=CreateService(hManager,rootkitname,rootkitname,SERVICE_ALL_ACCESS,SER VICE_KERNEL_DRIVER, SERVICE_BOOT_START,SERVICE_ERROR_NORMAL, \rootkpath,NULL,NULL,NULL, NULL,NULL,NULL);
StartService(hService,NULL,NULL);
This code create service, but it have mistake. In Builder6 i have this mistake:
[C++ Error] Unit1.cpp(60): E2451 Undefined symbol 'LPVTSTR'
[C++ Error] Unit1.cpp(60): E2379 Statement missing ;
[C++ Error] Unit1.cpp(61): E2451 Undefined symbol 'rootkpath'
[C++ Error] Unit1.cpp(63): E2206 Illegal character '\' (0x5c)
[C++ Error] Unit1.cpp(63): E2227 Extra parameter in call to __stdcall CreateServiceA(void *,const char *,const char *,unsigned long,unsigned long,unsigned long,unsigned long,const char *,const char *,unsigned long *,const char *,const char *,const char *)
Please, help me. Target my application is : user don't can closed my program from Task Manager.
LPVTSTR is not a thing, google suggests LPCTSTR (no idea if that is correct). Backslashes in C strings have to be doubled, so rootkpath="C:\\Users\\Admin\\...
In the call to CreateService - \rootkpath should be just rootkpath and remove one of the NULLs at the end, you have one too many.

How do I use std::bind when registering a function in Lua?

In the question How to register member function to lua without lua bind in c++ one answer suggested the following code:
class C {
public:
void blah(lua_State* L);
};
C inst;
lua_pushcclosure(L, std::bind(&C::blah, &inst, std::placeholder::_1), 0);
lua_setglobal(L, "blah");
(Quoted as it stood, including the small error in std::placeholders)
However, I cuold not get that to work. The error message I got back states that the function returned by std::bind can't be converted to a lua_CFunction.
I have also tried changing the return type of blah to int, but I get the same error message. If it's helpful to anyone, the full error message is:
Error C2664 'void lua_pushcclosure(lua_State *,lua_CFunction,int)': cannot convert argument 2 from 'std::_Binder<std::_Unforced,int (__thiscall C::* )(lua_State *),C *,const std::_Ph<1> &>' to 'lua_CFunction'
I even tried to change &C::blah to &inst.blah, but that unsurprisingly didn't work either.
Has anyone gotten it to work? Or is it just not meant to work?

C++ error C2664 with CStrings

I have some old C++ file which I know used to compile. I have created a new install of Visual C++ version 6.
I am getting lots of compile errors with CStrings about not being able to convert to const char *
Here's an example.
CString dogs = "test";
writeoutfile(dogs, 1);
void Crender::writeoutfile(CString data, long data_size) {}
I get this error:
error C2664: 'void __thiscall Crender::writeoutfile(const char *,long)' : cannot convert parameter 1 from 'class CString' to 'const char *'
Is there some way I can get round this?
You have to get the raw pointer to the char field. This can be done with
CString::GetBuffer()
so you could call
writeoutfile(dogs.GetBuffer(), 1);
CString should convert to const char*. Is it a Unicode build? That's the only explanation I can think of.
GetBuffer() is for getting a writeable pointer to the data contained inside CString. Don't do that!

How to wrap a C++ function?

I'm trying to wrap a c++ function called i_receive() by following this tutorial, I first created a wrap.c file, the content of this file is like this:
int i_receive(const uint32_t *f, int32_t t){
static int (*real_i_receive)(const uint32_t *, int32_t)=NULL;
printf("hello world");
return real_i_receive;
}
I compiled this file with gcc -fPIC -shared -o wrap.so wrap.c -ldl, when I used the LD_PRELOAD to run some C++ code with LD_PRELOAD=/full/path/to/wrap.so ./mycppcode I got this message:
ERROR: ld.so: object '/full/path/to/wrap.so' from LD_PRELOAD cannot be preloaded: ignored`.
I was guessing the reason might be that the wrap file is a C file, and I'm using it with C++ code, am I right?
I changed the file to wrap.cc with the same content, when compiling in the same way as before, I got:
ERROR: invalid conversion from 'int (*)(const uint32_t*, int32_t)' to 'int'
First of all, your 2nd error your are getting becase you are returning a Pointer to function type instead of a int type.
If you want to return an int, call the function from the code :
return real_i_receive(f,t);
Notice the "()" which means a function call.
Regarding your guess : it doesn't matter if you are using C or C++ code, the libaries are all assembly code.
One difference between exporting C functions and C++ functions is the name mangling. You would rather export a function as a C function to be able to access it inside your library through unmagled name.
To export a function without name mangling it, you can use extern "C" .
Replace
return real_i_receive;
with
return real_i_receive(f, t);
As it is, the return type of your function is int but you're returning a function pointer.

c++ pointers to overloaded functions

I'm trying to expose a overloaded function using boost::python.
the function prototypes are:
#define FMS_lvl2_DLL_API __declspec(dllexport)
void FMS_lvl2_DLL_API write(const char *key, const char* data);
void FMS_lvl2_DLL_API write(string& key, const char* data);
void FMS_lvl2_DLL_API write(int key, const char *data);
I'v seen this answer: How do I specify a pointer to an overloaded function?
doing this:
BOOST_PYTHON_MODULE(python_bridge)
{
class_<FMS_logic::logical_file, boost::noncopyable>("logical_file")
.def("write", static_cast<void (*)(const char *, const char *)>( &FMS_logic::logical_file::write))
;
}
results with the following error:
error C2440: 'static_cast' : cannot convert from 'overloaded-function' to 'void (__cdecl *)(const char *,const char *)'
None of the functions with this name in scope match the target type
trying the following:
void (*f)(const char *, const char *) = &FMS_logic::logical_file::write;
results:
error C2440: 'initializing' : cannot convert from 'overloaded-function' to 'void (__cdecl *)(const char *,const char *)'
None of the functions with this name in scope match the target type
what's wrong and how to fix it?
EDIT
I forgotten to mention a few things:
I'm using vs2010 pro on win-7
write is a member function of logical_file
FMS_logic is a namespace
Well the second attemp should work, if write is a pure function. From your code it seems you do have a memberfunction. Pointers to member-functions are ugly, you'd rather use a function object.
However: you would have to post the whole code, it is not clear whether write is a member-function or not.
Edit: if it is a member-function of FMS_logic::logical_file the syntax would be:
void (FMS_logic::logical_file::*f)(const char *, const char *) = &FMS_logic::logical_file::write;
This just applies for non-static member function, i.e. if a function is static or logical_file is just a namespace it is as you wrote it before.
Your code doesn't work because your function pointer type is wrong. You need to include all type qualifiers (your DLL qualifier is missing) and, as Klemens said, the class name. Putting this together, your code should read
.def("write", static_cast<void FMS_lvl2_DLL_API
(FMS_logic::logical_file::*)(const char *, const char *)>
(&FMS_logic::logical_file::write))
Thanks for the hint with the static_cast<>, I had the same problem as you, just without the dllexport, and after adding the static_cast it works :-)