tags:

views:

120

answers:

1

Hello All,

Good day.

I'm new to C# and trying to call functions from a DLL (C++ ObjGen). I'm getting this message and can't figure out why. Here's the code:

object[] objID = new object[] { ID };

ObjGen.Invoke(InvokeEnum.Query_State, objID);

Dll code

///////////////////////

INVOKE_FUNC_IMPLEMENT(Query_State, CUtil::GetState)

///////////////////////

bool CUtil::GetState(InvokeEnum methodID, SAFEARRAY * psa)
{
    UNIT_ID UID = (UNIT_ID)PARAM_LONG(0);

    CUtil::Instance()->NotifyUpdateState(UID);
    for(int slot = 0; slot < SLOT_ID_MAX; slot++)
     g_CManager.m_PJAssociArray[UID][slot] = 0;

    return true;
}

There is a loop called the top Invoke function. When objID = 1 Or 2 Or 3, the function worked very well. But when objID = 4. the function exception.

What could be the reason? Issue in C# or Dll file?

Is there something error in the Instance() OR NotifyUpdateState() ? i can't do the judgement.

thank you.

+1  A: 

You are creating an array of objects in which an object of ID is one element in that array. And you are passing it into a method, the said array objID

Can you include a code sample of what you are trying to achieve?

It is not very clear.

What is ID? Has ID been instantiated with the new? What is ObjGen?

Do you have the function 4 in your dll, if not that explains why you got a null reference exception. Double check your DLL and make sure you are calling the function 4.

Hope this helps you in giving you hints? Best regards, Tom.

tommieb75
Hello tommieb, I updated some DLL c++ code here.btw, The ID = 4 is not a specially function in DLL file. It is only a array value.thank you.
Nano HE
That is a COM object you are calling in the DLL? Maybe you need to check the method interop call, I noticed there is a SAFEARRAY, are you doing anything with that, maybe pass null into it on the C# side and see what happens?
tommieb75
@tom, Yes, this is a COM obj called in the DLL. I already found the root cause. The ObjGen not initialized finished when i try to invoke the DLL function. The ObjGen initialized at another thread. But the ObjGen.Invok generated by different thread. It is faster than the initialization thread.
Nano HE
@Nano HE: Great to hear you got your issue sorted! :) Good luck and take care! :)
tommieb75