
Untitled
By: a guest on
Jun 20th, 2012 | syntax:
None | size: 1.14 KB | hits: 12 | expires: Never
JNA Error at Program Exit
__declspec(dllexport) extern "C"
char** get_prop_types( int* count ) {
const vector<string>& r = prop_manager::get_prop_types();
char **p = (char**)malloc( r.size() );
char **ptr = p;
for( vector<string>::const_iterator it = r.begin(); it!=r.end() ; ++it ) {
*p = (char*)malloc( it->size() );
strcpy(*p++,it->c_str());
}
*count = r.size();
return ptr;
}
public interface Arch extends Library {
public Pointer get_prop_types( IntByReference size );
}
static Arch theLib; //initialization not shown
public static String[] getPropTypes() {
IntByReference size = new IntByReference();
Pointer strs = theLib.get_prop_types(size);
//free is apparently handled for us?
return strs.getStringArray(0, size.getValue());
}
public static void main( String[] args ) {
System.out.println( Arrays.toString(getPropTypes()) );
}
The instruction at "%08X" referenced memory at "%08x". The memory could not be "read".
*p = (char*)malloc( it->size() );
*p = (char*)malloc( it->size() + 1);
char **p = (char**)malloc( r.size() );
char **p = (char**)malloc( r.size() * sizeof(char *) );