部分代码如下:
int k=1;
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)smooth1,&k,NULL,NULL);
其中的smooth1()函数:
void smooth1(int i)
{
int j=i;
return;
}
我在int j=i;设置断点,i的值为34600292,请问这是怎么回事?
万分感谢!!

解决方案 »

  1.   

    你传的是一个局部变量的地址,这块内存在函数结束后会释放掉的,你直接传值好了
    部分代码如下:
    int k=1;
    CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)smooth1,(LPVOID)k,NULL,NULL);
    其中的smooth1()函数:
    DWORD WINAPI smooth1(LPVOID i)
    {
    int j=(int)i;
    return 0;
    }
      

  2.   

    谢谢楼上的仁兄,现在我换成参数为结构的,又有毛病了:
    1.h中部分代码:
    void *smooth1(void *smarg);
    typedef struct{
    LPSTR lpNewDIBBits;
    LPSTR lpDIBBits;
    LONG lWidth;
    }smstruct;1.cpp中部分代码:
    smstruct argm1;//smstruct为一结构类型
    argm1.lpNewDIBBits=lpNewDIBBits;//为结构中各成员赋值
    argm1.lpDIBBits=lpDIBBits;
    argm1.lWidth=lWidth;
    CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)smooth1,&argm1,NULL,NULL);1.cpp中的smooth1()函数:
    void *smooth1(void *smarg)
    {
       smstruct *smarg1;
       smarg1=(smstruct *)smarg;
    ............................//此时结构变量smarg1中的成员值不正确
       return 0;
    }
    在smooth1()函数中,smarg1中的成员值传递不正确,请问这是怎么回事,应怎样修改?
    谢谢!!
      

  3.   

    smstruct *argm1=new smstruct;//smstruct为一结构类型,分配到堆上
    argm1->lpNewDIBBits=lpNewDIBBits;//为结构中各成员赋值
    argm1->lpDIBBits=lpDIBBits;
    argm1->lWidth=lWidth;
    CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)smooth1,(LPVOID)argm1,NULL,NULL);
    1.cpp中的smooth1()函数:
    void *smooth1(LPVOID smarg)
    {
       smstruct *smarg1=(smstruct *)smarg;
    ............................
       delete smarg1;
       return 0;
    }