ODD __gc problem 
Author Message
 ODD __gc problem

I've written a managed C++ DLL to interface to an unmanaged legacy DLL.
However I am having a problem, in one call I have to allocate a char buffer,
pass it to the interface then return it as a CLR String. When I allocate the
__gc char array I am getting a unhandled exception with the informative
message "There is no source code for the current location". I have no
indication of what the error is or why I am receiving it. Any help would be
greatly appreciated.

BTW the class is declared __gc as well.

----------------------------CODE-----------------------------------
String * GM5API::DS_Fetch(long hand)

{

unsigned char pBuff __gc[] = new unsigned char __gc[32768]; //This line
throws the exception!

unsigned char __pin * pTmp = &pBuff[0];

long lRet = 0;

int iCount = 0;

wchar_t pWchar __gc[];

if(NULL != gmw_ds_fetch)

lRet = gmw_ds_fetch(hand,(char *)pTmp,32768,500);

UnicodeEncoding *use = new UnicodeEncoding();

iCount = use->GetCharCount(pBuff,0,strlen((char *)pTmp));

pWchar = new wchar_t __gc[iCount+1];

use->GetChars(pBuff,0,iCount,pWchar,0);

String *buff = new String(pWchar);

return buff;

Quote:
}



Sat, 03 Dec 2005 22:43:05 GMT  
 ODD __gc problem
After much head scrathing and searching I have found a solution. It seems to
be much simpler than my original approach and works consistenly. I am
posting it here for completion. (And if anyone can see an obvious flaw I
would love to hear of it.)

-------------------------CODE-------------------------------
using System::Runtime::InteropServices;
String * GM5API::DS_Fetch(long hand)

{

char *pBuff = new char [32768];

long lRet = 0;

int iCount = 0;

if(NULL != gmw_ds_fetch)

lRet = gmw_ds_fetch(hand,pBuff,32768,500);

String *buff = Marshal::PtrToStringAnsi(pBuff);

free(pBuff);

return buff;

Quote:
}



Quote:
> I've written a managed C++ DLL to interface to an unmanaged legacy DLL.
> However I am having a problem, in one call I have to allocate a char
buffer,
> pass it to the interface then return it as a CLR String. When I allocate
the
> __gc char array I am getting a unhandled exception with the informative
> message "There is no source code for the current location". I have no
> indication of what the error is or why I am receiving it. Any help would
be
> greatly appreciated.

> BTW the class is declared __gc as well.

> ----------------------------CODE-----------------------------------
> String * GM5API::DS_Fetch(long hand)

> {

> unsigned char pBuff __gc[] = new unsigned char __gc[32768]; //This line
> throws the exception!

> unsigned char __pin * pTmp = &pBuff[0];

> long lRet = 0;

> int iCount = 0;

> wchar_t pWchar __gc[];

> if(NULL != gmw_ds_fetch)

> lRet = gmw_ds_fetch(hand,(char *)pTmp,32768,500);

> UnicodeEncoding *use = new UnicodeEncoding();

> iCount = use->GetCharCount(pBuff,0,strlen((char *)pTmp));

> pWchar = new wchar_t __gc[iCount+1];

> use->GetChars(pBuff,0,iCount,pWchar,0);

> String *buff = new String(pWchar);

> return buff;

> }



Sun, 04 Dec 2005 03:12:37 GMT  
 ODD __gc problem
Too soon to announce success.... the new code exhibits the same behavour
just not as often....
Help please!


Quote:
> I've written a managed C++ DLL to interface to an unmanaged legacy DLL.
> However I am having a problem, in one call I have to allocate a char
buffer,
> pass it to the interface then return it as a CLR String. When I allocate
the
> __gc char array I am getting a unhandled exception with the informative
> message "There is no source code for the current location". I have no
> indication of what the error is or why I am receiving it. Any help would
be
> greatly appreciated.

> BTW the class is declared __gc as well.

> ----------------------------CODE-----------------------------------
> String * GM5API::DS_Fetch(long hand)

> {

> unsigned char pBuff __gc[] = new unsigned char __gc[32768]; //This line
> throws the exception!

> unsigned char __pin * pTmp = &pBuff[0];

> long lRet = 0;

> int iCount = 0;

> wchar_t pWchar __gc[];

> if(NULL != gmw_ds_fetch)

> lRet = gmw_ds_fetch(hand,(char *)pTmp,32768,500);

> UnicodeEncoding *use = new UnicodeEncoding();

> iCount = use->GetCharCount(pBuff,0,strlen((char *)pTmp));

> pWchar = new wchar_t __gc[iCount+1];

> use->GetChars(pBuff,0,iCount,pWchar,0);

> String *buff = new String(pWchar);

> return buff;

> }



Sun, 04 Dec 2005 04:04:23 GMT  
 ODD __gc problem

--------------------

Quote:

> Subject: ODD __gc problem
> Date: Tue, 17 Jun 2003 10:43:05 -0400
> Lines: 45
> I've written a managed C++ DLL to interface to an unmanaged legacy DLL.
> However I am having a problem, in one call I have to allocate a char
buffer,
> pass it to the interface then return it as a CLR String. When I allocate
the
> __gc char array I am getting a unhandled exception with the informative
> message "There is no source code for the current location". I have no
> indication of what the error is or why I am receiving it. Any help would
be
> greatly appreciated.

> BTW the class is declared __gc as well.

Hi Charles,

Compile using -Zi, and if you're using VC 7.1, /link /assemblydebug, and
you should be able to pin point the place where the exception is occurring.

--
Tanveer Gani, Visual C++ Team
This posting is provided AS IS with no warranties, and confers no rights.



Sun, 11 Dec 2005 02:04:39 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Object __gc* to Object __gc* __gc* ?

2. __gc or not __gc

3. Question about __gc * __gc *

4. Declaration problem with __gc[] & a MemoryStream

5. Very odd string problem

6. Odd ADSI Problem

7. Odd Setup Problems

8. Odd problem with System.Collections.SortedList

9. Odd scanf problem

10. odd pointer dereference problem

11. Problem with odd loop when passing float to function

12. Problem with odd loop when passing float to function

 

 
Powered by phpBB® Forum Software