[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Runtime error: application has requested runtime to terminate it in an unusual way - calling C# from C++

Posted on 2003-11-25
8
Medium Priority
?
3,025 Views
Last Modified: 2010-05-18
I have a C# DLL that uses SQLDMO and I have a C++ program that calls it.  I can run it in the debugger and the code goes through and calls the DLL and executes the function just like I would expect it to but when the function exits I get this error:

---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Runtime Error!

Program: C:\C# DLL\TestProgram2\Debug\TestProgram2.exe



This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.


---------------------------
OK  
---------------------------


any ideas?
0
Comment
Question by:emily_hall
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9819985
What call conventions are you using? How do you call from C++ to C#?
0
 
LVL 1

Author Comment

by:emily_hall
ID: 9820015
This is my C++ code:

::CoInitialize(NULL);

SetConnectionString(connectionString);
      
_DbClassPtr p;
p.CreateInstance("DatabaseLibrary.DbClass");
m_DLLInterfacePtr = p.GetInterfacePtr();

m_DLLInterfacePtr->loadStoredProcedureDetails(m_connectionString);

loadStoredProcedureDetails returns a bool but I have tried returning void and the same thing happens...
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9820155
Is m_connectionString a BSTR? Who allocates the memory and who is deallocating it?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:emily_hall
ID: 9820698
m_connectionString is a char*.

and that is the code for the whole function - connectionString is passed in.

0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9826732
I think that's the problem COM usually marhals string as BSTR and not as char*. The process tries to free memory that it doesn't own.
0
 
LVL 10

Accepted Solution

by:
ptmcomp earned 300 total points
ID: 9826752
Did you compile it with UNICODE or ANSI option?
0
 
LVL 1

Author Comment

by:emily_hall
ID: 9826820
A coworker of mine actually found the problem but we so far haven't been able to figure out how to fix it.  The problem isn't with that function but with the one that is called after it:

int machineId = m_DLLInterfacePtr->executeStoredProcedure("sp_GetMachineId", m_connectionString, (tagSAFEARRAY *)getMachineId, 3);

the problem is with the 3rd parameter which I typecast to a tagSAFEARRAY* in order to make it compile.  What that is is an array of struct.  On the other side, the C# is expecting an array of struct but it is dying when it tries to pass that through...

0
 
LVL 1

Author Comment

by:emily_hall
ID: 11371515
hey just going through my old questions trying to tidy things up.  thanks for the help.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question