C Programming: malloc() inside another function

后端 未结 9 1103
暖寄归人
暖寄归人 2020-11-22 06:47

I need help with malloc() inside another function.

I\'m passing a pointer and size to the fu

9条回答
  •  长发绾君心
    2020-11-22 07:22

    The only way I could get pointer to a pointer solution to work for a similar problem I was having for this function

        BOOL OpenBitmap2 ( LPCTSTR pszFileName, char** pszBMPFile)  
    

    Was by assigning a temporary pointer to store the address

        char* BMPFile;
        { BMPFile = (char*)GlobalAlloc(GPTR, dwFileSize + 1);   // allocate storage using GlobalAlloc + 1 for null term string
    

    then reassigning it

        {* pszBMPFile = BMPFile; return (0);} // Error = False
    

    Any comment on why using "* pszBMPFile" directly with GlobalAlloc didn't work would be appreciated. I answered my own question. I forgot to carry the "*" through with pszBMPFile in the other lines of code. Good lessons from all the contributors. Many thanks.

提交回复
热议问题