Click here to Skip to main content
       

Managed C++/CLI

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
AdminThe C++ / CLI is for managed and mixed-mode C++ programming onlyadminChris Maunder9 Jan '06 - 9:36 
This message board is for managed and mixed-mode C++ programming only: Managed C++ in VC++.NET or C++/CLI. Please post all standard C++ programming questions in the Visual C++ board[^].
 
cheers,
Chris Maunder
CodeProject.com : C++ MVP

QuestionType casting in C++\CLI projectmemberfor study19hrs 19mins ago 
I have project which I am compiling with /clr. I have a class like below..
 
ref class A
{
public:
 void CheckValue(void * test);
 typedef ref struct val
{
 std::string *x;
}val_t;
 
};
 
in my implementation I ahve to use something like below..
 
void A::CheckValue(void *test)
{
 a::val_t^ allVal = (a::val_t^)test;
}
 
in my main I have used like..
 

int main()
{
A^ obj = gcnew A();
a::val_t valObj = new std::string("Test");
obj->CheckValue((void*)valObj);
}
 
I am getting type cast error and two places - obj->CheckValue((void*)valObj); and at obj->CheckValue((void*)valObj); error C2440: 'type cast' : cannot convert from 'void*' to 'A::val_t ^'
 
This snippet is just to show behavior at my end and I ahve to use it this way only. Earlier I was running it using non /clr so it compiled fine.
 
Now question I have how can I make this type casting work in C++/CLI type project?
AnswerRe: Type casting in C++\CLI projectmemberDavid Knechtges12hrs 31mins ago 
You are mixing the two - managed and unmanaged - void * is unmanaged and val_t is managed. You need to do a conversion in order to get this to work. Here is a similar question:
 
http://stackoverflow.com/questions/6903208/cli-c-void-to-systemobject[^]
Questionetting Access Violation Exception -Attempted to read or write protected memory - when trying to convert unmanaged array of structures into managed class in Vb.Net (VS2010,4.0 framework) in Windows 7 -64 bit mode.groupVijaySandur25 Apr '13 - 3:44 
Getting Access Violation Exception when trying to convert unmanaged array of structures into managed in Vb.Net(VS2010,4.0 framework) in Windows 7 -64 bit mode.
Sample Source Code
 
_
Public Class vb_menu_dotnet
Public level As Short
Public menu_id As String
Public short_desc As String
Public parent_id As String
Public access As Short
Public flag As Short
Public menu_desc As String
End Class
 

Dim current As IntPtr
Dim outArray As IntPtr
Dim manArray(100) As vb_menu_dotnet
 
vb_dotnet_get_menu_hierarchy(p_menu_handle, p_apl_id, outArray) //C API call
current = outArray
 
Dim j As Integer
For j = 1 To 100
manArray(j) = New vb_menu_dotnet()
Marshal.PtrToStructure(current, manArray(j)) //Access Violation Exception
Vijay

AnswerRe: etting Access Violation Exception -Attempted to read or write protected memory - when trying to convert unmanaged array of structures into managed class in Vb.Net (VS2010,4.0 framework) in Windows 7 -64 bit mode.memberJohn Schroedl25 Apr '13 - 7:52 
You may need to try a VB.NET forum. This is for C++/CLI code.
AnswerRe: etting Access Violation Exception -Attempted to read or write protected memory - when trying to convert unmanaged array of structures into managed class in Vb.Net (VS2010,4.0 framework) in Windows 7 -64 bit mode.mvpRichard MacCutchan25 Apr '13 - 22:29 
Dim current As IntPtr
Dim outArray As IntPtr
Dim manArray(100) As vb_menu_dotnet
 
vb_dotnet_get_menu_hierarchy(p_menu_handle, p_apl_id, outArray) //C API call
You have not initialised any of the pointers that you are sending to the C-language library. Take a look at this P/Invoke tutorial[^] for more information.
Use the best guess

GeneralRe: etting Access Violation Exception -Attempted to read or write protected memory - when trying to convert unmanaged array of structures into managed class in Vb.Net (VS2010,4.0 framework) in Windows 7 -64 bit mode.memberTripurari Chaudhary13 May '13 - 23:43 
Hi ,
whatever database u r acessing or data retrieval policy u might be using for e.g INI file,must be in Read Mode,Try to make it Write protected
QuestionRe: etting Access Violation Exception -Attempted to read or write protected memory - when trying to convert unmanaged array of structures into managed class in Vb.Net (VS2010,4.0 framework) in Windows 7 -64 bit mode.mvpRichard MacCutchan13 May '13 - 23:50 
Did you actually read the OP's question?
Use the best guess

AnswerRe: etting Access Violation Exception -Attempted to read or write protected memory - when trying to convert unmanaged array of structures into managed class in Vb.Net (VS2010,4.0 framework) in Windows 7 -64 bit mode.memberTripurari Chaudhary13 May '13 - 23:44 
Hi ,
whatever database  u r acessing or data retrieval policy u might be using for e.g INI file,must be in Read Mode,Try to make it Write protected

QuestionAd Hoc routing protocolmember3bood.ghzawi18 Apr '13 - 2:43 
can anyone help me finding the source code or the simulation of the Dual Busy Tone Multiple Access (DBTMA) protocol ????
 
regards...
Sniff | :^) Unsure | :~ WTF | :WTF:

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 24 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid