Hello All,

I am trying to compile the C++ program. But I am getting weired compilation error.

++++++++++++++++++++++++++++++++++++++++++++++++++++++
1>------ Build started: Project: HelloPras, Configuration: Debug Win32 ------
1>Compiling...
1>HelloPras.cpp
1>c:\documents and settings\prash\my documents\visual studio 2008\projects\hellopras\hellopras\hellopras.cpp(15) : error C2819: type 'JavaVM_' does not have an overloaded member 'operator ->'
1> c:\program files\java\jdk1.5.0\include_5.0\jni.h(1899) : see declaration of 'JavaVM_'
1> did you intend to use '.' instead?
1>c:\documents and settings\prash\my documents\visual studio 2008\projects\hellopras\hellopras\hellopras.cpp(15) : error C2232: '->JavaVM_::GetEnv' : left operand has 'struct' type, use '.'
1>c:\documents and settings\prash\my documents\visual studio 2008\projects\hellopras\hellopras\hellopras.cpp(17) : error C3861: 'parse_agent_options': identifier not found
1>c:\documents and settings\prash\my documents\visual studio 2008\projects\hellopras\hellopras\hellopras.cpp(26) : error C2819: type '_jvmtiEnv' does not have an overloaded member 'operator ->'
1> c:\program files\java\jdk1.5.0\include_5.0\jvmti.h(1529) : see declaration of '_jvmtiEnv'
1> did you intend to use '.' instead?
.........................
++++++++++++++++++++++++++++++++++++++++++++++++++++++

The source code for my "HelloPras.cpp" code is:-

++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include "stdafx.h"
#include "C:\Program Files\Java\jdk1.5.0\include_5.0\jvmti.h"
#include "C:\Program Files\Java\jdk1.5.0\include_5.0\jni.h"

static jrawMonitorID agent_lock;

JNIEXPORT jint JNICALL
Agent_OnLoad(JavaVM *vm, char *options, void *reserved) {
jvmtiEnv *jvmti;
jvmtiError error;
jint res;
jvmtiCapabilities capabilities;
jvmtiEventCallbacks callbacks;

res = (*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1);

parse_agent_options(options);

(void)memset(&capabilities,0, sizeof(capabilities));
capabilities.can_generate_all_class_hook_events = 1;
capabilities.can_tag_objects = 1;
capabilities.can_generate_object_free_events = 1;
capabilities.can_get_source_file_name = 1;
capabilities.can_get_line_numbers = 1;
capabilities.can_generate_vm_object_alloc_events = 1;
error = (*jvmti)->AddCapabilities(jvmti, &capabilities);

(void)memset(&callbacks,0, sizeof(callbacks));
callbacks.VMStart = &cbVMStart;
callbacks.VMInit = &cbVMInit;
callbacks.VMDeath = &cbVMDeath;
callbacks.ObjectFree = &cbObjectFree;
callbacks.VMObjectAlloc = &cbVMObjectAlloc;
callbacks.ClassFileLoadHook = &cbClassFileLoadHook;
error = (*jvmti)->SetEventCallbacks(jvmti, &callbacks,
(jint)sizeof(callbacks));

error = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
JVMTI_EVENT_VM_START, (jthread)NULL);
error = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
JVMTI_EVENT_VM_INIT, (jthread)NULL);
error = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
JVMTI_EVENT_VM_DEATH, (jthread)NULL);
error = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
JVMTI_EVENT_OBJECT_FREE, (jthread)NULL);
error = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
JVMTI_EVENT_VM_OBJECT_ALLOC, (jthread)NULL);
error = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, (jthread)NULL);

error = (*jvmti)->CreateRawMonitor(jvmti, "agent data", &(agent_lock));

return JNI_OK;
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++

Also the headers I have included in My program can be found at:-
1) JNI.h :- http://xdprof.sourceforge.net/doxyg..._8h-source.html
2)jvnti,h:- http://subversion.gvsig.org/gvSIG/t...jni_w32/jvmti.h

Please help me why I am getting above error?
The source program above I have downloaded is sample code available from tutorial website & should work fine. But I don't know why its throwing above error.

I am using compiler in Visual C++ 2008 for compiling this file.

Many Thanks in advance.

------Pras

Member Avatar for jencas

res = vm->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION_1);

(*vm) is the object pointed to by vm, and this vm object has no operator ->. Instead of "vm->" you can also write "(*vm). ".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.