How to modify content of the original variable which is passed by value?

后端 未结 4 725
独厮守ぢ
独厮守ぢ 2020-12-19 11:01

There is an existing API function which does only allow the plugin(DLL) to receive three parameters and perform some action:

int ProcessMe(int nCommand, unsi         


        
4条回答
  •  庸人自扰
    2020-12-19 11:56

    Try this... it is POSSIBLE!!!

    include

    int ProcessMe(int nCommand, unsigned int wParam, long lParam)

    {

    int *nCommand_ptr = (int*)nCommand;
    unsigned int *wParam_ptr = (unsigned int*)wParam;
    long *lParam_ptr = (long*)lParam;
    *nCommand_ptr = 10;
    *wParam_ptr = 10;
    *lParam_ptr = 10;
    return 0;
    

    }

    int main(){

    int nCommand = 5;
    unsigned int wParam = 5;
    long lParam = 5;
    printf("\n %d %u %lu",nCommand,wParam,lParam);
    ProcessMe((int)&nCommand,(unsigned int)&wParam,(long)&lParam);
    printf("\n %d %u %lu",nCommand,wParam,lParam);
    return 0;
    

    }

    Output:

    $>g++ passbyref.cc

    $>./a.out

    5 5 5

    10 10 10$>

提交回复
热议问题