473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

NullReferenceException in MC++

Hi,

I am new to C++ & MC++. I am trying to write a wrapper class for exsiting
code which uses libraries(Adobe Framemaker) to open documents. These
libraries are written in C++.

The code is :-

.......
public __gc class Framemaker
{

bool ConnectToFrameSession(String* strProgID)
{
char* strProg = (char*)(void*)Marshal::StringToHGlobalAnsi(strProg ID);
ConnectToFrame(strProg);

return true;
}
.......

int ConnectToFrame(char *strProg)
{
StringT opt_progid;
CLSID pclsid;
LPOLESTR progStr;
HRESULT res;
F_ObjHandleT docId;

// Get the process name.
opt_progid = F_StrCopyString((StringT)strProg);

// Convert the process name into a GUID
progStr = (OLECHAR*)malloc( WBUFLEN*sizeof(wchar_t) );
if(0 == MultiByteToWideChar(CP_ACP, 0, (char *)opt_progid, -1, progStr,
WBUFLEN ))
{
fprintf(stderr, "failed to allocate\n");
return(1);
}
........

Now the code bombs while doing a malloc or calling any native frame
functions in the function above. It says Object Not Set or NullRefernecce
Exception.

Is it beacuse i am trying to mix managed and unmanaged code?
How shld i go abt solving ths problem ?

Also this code runs fine if i make a console application & run it.
I am trying to make wrapper dll which would be calkled by C#.
Only differnec i see is __GC.

Pls guide me.

Thanks,
Gurminder

Nov 17 '05 #1
1 1178
Gurminder wrote:
Hi,

I am new to C++ & MC++. I am trying to write a wrapper class for exsiting
code which uses libraries(Adobe Framemaker) to open documents. These
libraries are written in C++.

The code is :-

......
public __gc class Framemaker
{

bool ConnectToFrameSession(String* strProgID)
{
char* strProg = (char*)(void*)Marshal::StringToHGlobalAnsi(strProg ID);
ConnectToFrame(strProg);

return true;
}


I don't think this is the problem, but you're missing a call to
Marshal::FreeHGlobal(strProg), which is a memory leak. Also, I'd use
..ToPointer() instead of casting to void*. That void* casting looks very
suspicious to me.

Can you try this?

bool ConnectToFrameSession(String* strProgID)
{
IntPtr hProg = Marshal::StringToHGlobalAnsi(strProgID);
char* strProg = reinterpret_cast<char*>(hProg.ToPointer());
ConnectToFrame(strProg);
Marshal::FreeHGlobal(hProg);
return true;
}

I'm using the above code without any problem in my managed->unmanaged
interface.

Or possibility your unmanaged function does something wrong, which I
can't verify.

Tom
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in...
0
by: Daniel Lidström | last post by:
Hi, I've been trying a long time now to generate some XML using MC++ and XmlSerializer. I have a piece of C# code that produces exactly what I want, but I simply can't get the MC++ code to write...
2
by: Raed Sawalha | last post by:
i have a windows form(Main) with listview, when click an item in listview i open other window form (Sub) which generate the selected item from parent window in as treeview items when click any item...
2
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a...
2
by: Lev | last post by:
Hi, I have some code that does reflection on an assembly I load. When I try to get the attributes on one of the methods implemented in the assembly, the MC++ version does not return anything....
0
by: Maxwell | last post by:
Hello, I recently completed a MC++ (VS2003) DLL that wraps a non MFC C++ DLL and need to use it in a MC++ Console Application (no forms/guis of any kind just output to console). Trouble is...
3
by: Marcus Kwok | last post by:
I have been staring at this code and I cannot see what is wrong with it. I am getting a NullReferenceException when trying to pass a value struct to a method. This exception only happens in...
8
by: WebSnozz | last post by:
I have an application written in C that does a lot of low level stuff. It does a lot of things like casting from void*'s. I want to create a new GUI for it in either C# or MC++, but reuse the...
3
by: Bruno LIVERNAIS | last post by:
Hi, We are currently installing a DB2 V9 ESE on a Linux server (RHEL4U4-x86_64). Installation runs successfully on each node. Database user environment is OK and the instance is well created. To...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.