Click here to Skip to main content
15,949,686 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Initialize variable in static library Pin
Stuart Dootson29-Apr-09 0:36
professionalStuart Dootson29-Apr-09 0:36 
GeneralRe: Initialize variable in static library Pin
Maximilien29-Apr-09 0:43
Maximilien29-Apr-09 0:43 
GeneralRe: Initialize variable in static library Pin
Stuart Dootson29-Apr-09 0:46
professionalStuart Dootson29-Apr-09 0:46 
GeneralRe: Initialize variable in static library Pin
samira forooghi29-Apr-09 1:01
samira forooghi29-Apr-09 1:01 
GeneralRe: Initialize variable in static library Pin
Rajesh R Subramanian29-Apr-09 1:21
professionalRajesh R Subramanian29-Apr-09 1:21 
GeneralRe: Initialize variable in static library Pin
samira forooghi29-Apr-09 0:45
samira forooghi29-Apr-09 0:45 
AnswerRe: Initialize variable in static library Pin
Stuart Dootson29-Apr-09 0:45
professionalStuart Dootson29-Apr-09 0:45 
QuestionC++ / JNI object instance problems Pin
megaadam28-Apr-09 23:53
professionalmegaadam28-Apr-09 23:53 
I have just started at a new job. Here we are new to using JNI ( for bridging C++ / Java ). I am new to JNI so please forgive my noobness Smile | :)

In our (win32) Java app we are loading a C++ DLL. On the Java side we have several instances of "SomeJClass" each of these instances needs access to corresponding instance of "SomeCClass" on the DLL side. The DLL exposes entry-points such as GlobalDoSomethingInC(). Here I must call the instance method of Doer::DoSomethingInC(). So I need a smooth way to map the respective this-pointers. I also need to do the same mapping when a DLL thread discovers something interesting that it needs to notify the corresponding Java-instance of.

I can think of several solutions, but I do not like them too much. My question is, is there a better way than this ?

1 Java calls C:GetNewInstance(). This returns an int that is actually a pointer to the new C instance. Java stores it in m_myCInstance. Then Java calls GlobalDoSomethingInC(), and 1a

// DLL global<br />
void GlobalDoSomethingInC()<br />
{<br />
    // retrive this pointer<br />
    //calling back to Java:  <br />
    jobj tmpJ = NewGlobalRef( env, obj );<br />
    Doer* myDoer = <reinterpret_cast>( Doer )tmpJ->GetMyCInstance();<br />
    myDoer->DoSomething();<br />
    DeleteGlobalRef( env, tmpJ );<br />
    // Arrrrgh<br />
}<br />
</reinterpret_cast>

1b or:

    // for **every call** that Java adds a parameter, <br />
    //which is the stored int:m_myCInstance, and<br />
    Doer* myDoer = <reinterpret_cast>( Doer )instanceParam->DoSomethingInC();<br />
    // Can we do better that this?<br />
<br />
</reinterpret_cast>
2 For calling from C to Java, things look, maybe, better

In the constructor C calls back into Java and stores
the Java instance reference
in a member variable. m_myJInstance.<br />
In all subsequent calls m_myJInstance can be used to call back Java.<br />
In the destructor we need to call DeleteGlobalRef( env, m_myJInstance );<br />

Not too bad I suppose. But it really safe to store the jobject reference. I mean: What happens when the GC moves the object around?

3 Our present solution does "work". But it belongs on rather on http://www.codinghorror.com/blog/ Smile | :)

Another question, for JNI experts only. How much juice does it cost to do this sequence:
<br />
    jobj tmpJ = NewGlobalRef( env, obj );<br />
    tmpJ->GetMyCInstance();<br />
    DeleteGlobalRef( env, tmpJ );




Thanks
Adam



........................
Life is too shor

Questioncreating menus dynamically Pin
Farhat Aisha28-Apr-09 23:33
Farhat Aisha28-Apr-09 23:33 
AnswerRe: creating menus dynamically Pin
led mike29-Apr-09 4:21
led mike29-Apr-09 4:21 
QuestionClear X-Box from the system menu Pin
Shashi.Shinde28-Apr-09 23:24
Shashi.Shinde28-Apr-09 23:24 
AnswerRe: Clear X-Box from the system menu Pin
Stuart Dootson29-Apr-09 0:22
professionalStuart Dootson29-Apr-09 0:22 
AnswerRe: Clear X-Box from the system menu Pin
David Crow29-Apr-09 4:34
David Crow29-Apr-09 4:34 
Question[Message Deleted] Pin
Purish Dwivedi28-Apr-09 23:03
Purish Dwivedi28-Apr-09 23:03 
AnswerRe: Multilingual Application (old characters are not getting removed) Pin
Rajesh R Subramanian28-Apr-09 23:11
professionalRajesh R Subramanian28-Apr-09 23:11 
Answer[Message Deleted] Pin
Purish Dwivedi28-Apr-09 23:26
Purish Dwivedi28-Apr-09 23:26 
GeneralRe: Multilingual Application (old characters are not getting removed) Pin
Rajesh R Subramanian28-Apr-09 23:45
professionalRajesh R Subramanian28-Apr-09 23:45 
AnswerRe: Multilingual Application (old characters are not getting removed) Pin
CPallini28-Apr-09 23:31
mveCPallini28-Apr-09 23:31 
Answer[Message Deleted] Pin
Purish Dwivedi28-Apr-09 23:45
Purish Dwivedi28-Apr-09 23:45 
GeneralRe: Multilingual Application (old characters are not getting removed) Pin
CPallini28-Apr-09 23:50
mveCPallini28-Apr-09 23:50 
GeneralRe: Multilingual Application (old characters are not getting removed) Pin
Cedric Moonen28-Apr-09 23:53
Cedric Moonen28-Apr-09 23:53 
GeneralRe: Multilingual Application (old characters are not getting removed) Pin
CPallini29-Apr-09 0:07
mveCPallini29-Apr-09 0:07 
General[Message Deleted] Pin
Purish Dwivedi29-Apr-09 0:13
Purish Dwivedi29-Apr-09 0:13 
QuestionRe: Multilingual Application (old characters are not getting removed) [modified] Pin
CPallini29-Apr-09 0:18
mveCPallini29-Apr-09 0:18 
QuestionAdd text to mouse Cursor Pin
002comp28-Apr-09 21:26
002comp28-Apr-09 21:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.