G
Guest
I have a managed C++ dll,, which is called from C#. The managed C++ module
then calls a non-managed C++ dll which returns a linked list. If I pass in a
beginning node, and then have the non-managed C++ dll add links to the
existing node, everything works fine. If I pass in a pointer-to-a-pointer to
a linked list element, after returning from the function, the pointer has
undefined values for the two elements.
If I change the calling dll to unmanaged, it works fine.
Here is the code for the two sample modules:
The Managed dll code:
// LinkedListApp.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "IPrintMigrate.h" // the unmanaged dll header
int _tmain(int argc, _TCHAR* argv[])
{
LinkedList __nogc *linkedList = NULL;
LinkedList __nogc *ptr = NULL;
if (GetPSMPrinters("abcde", &linkedList))
{
ptr = linkedList;
while (ptr)
{
//paList->Add(new String(ptr->name));
printf("printer %s\n", ptr->name);
ptr = ptr->next;
}
}
return 0;
}
The Unmanged dll code:
// IPrintMigrate.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "IPrintMigrate.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
// This is an example of an exported variable
IPRINTMIGRATE_API int nIPrintMigrate=0;
// This is an example of an exported function.
IPRINTMIGRATE_API bool GetPSMPrinters(char *charIPAddress, LinkedList
**linkedList)
{
*linkedList = new LinkedList();
strcpy((*linkedList)->name, "first one");
LinkedList *a = new LinkedList();
strcpy(a->name, "second one");
a->next = NULL;
(*linkedList)->next = a;
return true;
}
What do I need to do so that I don't need to allocate the first node in the
calling routine?
- Bruce
then calls a non-managed C++ dll which returns a linked list. If I pass in a
beginning node, and then have the non-managed C++ dll add links to the
existing node, everything works fine. If I pass in a pointer-to-a-pointer to
a linked list element, after returning from the function, the pointer has
undefined values for the two elements.
If I change the calling dll to unmanaged, it works fine.
Here is the code for the two sample modules:
The Managed dll code:
// LinkedListApp.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "IPrintMigrate.h" // the unmanaged dll header
int _tmain(int argc, _TCHAR* argv[])
{
LinkedList __nogc *linkedList = NULL;
LinkedList __nogc *ptr = NULL;
if (GetPSMPrinters("abcde", &linkedList))
{
ptr = linkedList;
while (ptr)
{
//paList->Add(new String(ptr->name));
printf("printer %s\n", ptr->name);
ptr = ptr->next;
}
}
return 0;
}
The Unmanged dll code:
// IPrintMigrate.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "IPrintMigrate.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
// This is an example of an exported variable
IPRINTMIGRATE_API int nIPrintMigrate=0;
// This is an example of an exported function.
IPRINTMIGRATE_API bool GetPSMPrinters(char *charIPAddress, LinkedList
**linkedList)
{
*linkedList = new LinkedList();
strcpy((*linkedList)->name, "first one");
LinkedList *a = new LinkedList();
strcpy(a->name, "second one");
a->next = NULL;
(*linkedList)->next = a;
return true;
}
What do I need to do so that I don't need to allocate the first node in the
calling routine?
- Bruce