.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Pointer into array when calling unmanaged code on 64 bit

Posted By:      Posted Date: September 12, 2010    Points: 0   Category :.NET Framework
I need to write a .Net-Frontend for an unmanaged Windows DLL which contains an API that must not be changed. My frontend works perfectly with the 32-bit version of the DLL. I have trouble using the 64-bit version of the DLL, because some functions expect a void pointer and interpret it as a pointer into an integer array. I boiled the problem down to this simple function: extern "C" int PASCAL EXPORT ExportedFunction(void *data) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // Hier normaler Funktionsrumpf int *arr = (int *)data; arr[0]++; arr[1]++; arr[2]++; return sizeof(int); } Here is a stripped down version of my attempts to call "ExportedFunction": Imports System.Runtime.InteropServices Public Class Form1 Declare Function ExportedFunction Lib "testlib.dll" (<MarshalAs(UnmanagedType.I4)> ByRef parameter As Integer) As Integer Declare Function ExportedFunction2 Lib "testlib.dll" Alias "ExportedFunction" (ByVal parameter() As Integer) As Integer Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim arr() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} Dim intsize As Integer = ExportedFunction(arr(6)) Console.WriteLine("SizeOf int in DLL: " & intsize.ToString) Console.Wri

View Complete Post

More Related Resource Links

CLR Inside Out: Marshaling between Managed and Unmanaged Code


Marshaling is an important part of .NET interop. It allows you to call into unmanaged code from managed code. This column will help you get started.

Yi Zhang and Xiaoying Guo

MSDN Magazine January 2008

.NET Internals: Examine Running Processes Using Both Managed and Unmanaged Code


There are plenty of times when you need to get information on running processes, not the least of which is during performance tuning. Using the techniques in this article and special .NET classes you'll see how to get a process' ID, name, priority, number of threads, kernel handle, and memory consumption, as well as its user-mode, kernel-mode, and total elapsed running time and put them to use in a custom app called AssemblyBrowser.

Christophe Nasarre

MSDN Magazine October 2004

C++ and ATL: Use ATL Server Classes to Expose Your Unmanaged C++ Code as an XML Web Service


Throughout this issue, you'll read all about the promise of Web Services and how the .NET Framework enables Web Service development. Many people will also be building their Web Services atop C++ code and frameworks like ATL Server, particularly when performance is paramount. In this article, the authors show how fully functional Web Services are built using ATL Server and Visual Studio .NET. Beginning with unmanaged C++ classes, they add ATL attributes that make the code work over HTTP.

Kirk Fertitta and Chris Sells

MSDN Magazine December 2002

using managed code in unmanaged c++

I wanna use a managed c++ class and its functions (in which I wanna use interop services to wrap a COM based dll) in unmanaged codes is it possible? I mean, I feel like this maybe the case of JWNW(just will not work :D my alternate to IJW). This way seems to be scary and troubling  COM->C++/CLI->C++ and someone can remind me what was the function to call with System::Runtime::InteropServices (Visual c++ intellisense does not help me much there). Mmmm I had a few small projects calling unmanaged code in managed one ( using "pragma"s ) but I have no ideas for other way around. Can anyone direct me in right direction? I do not expect you to provide full working examples but seeing some conceptual FOO solutions would be most appreciated :D Thank you for your time :) Volkan

Sharing a file handler between managed and unmanaged code?

This is related to Interops, and sharing a file handler between a WPF UI and a native C++ DLL. I'm working on an application using MVVM as a guide. I want to use WPF for the UI, however it is a complex scientific application, which requires performance, and I am using C++ along with some GPU based code for all the modeling/processing. This is a Windows based app, no real network comm involved. I come across a challenge in terms of storing data. The data is multi-dimensional, and can be projected in many ways, while each projection can be processed/filtered in many ways too. I end up with a tree of data, with the raw data at the root and many branches. XML seems like an ideal way to store the information about this dataset, but as far as the raw data, it is not so convenient. I read about base64 encoding and the various binary-XML techniques, but see a major issue: the size of the converted data (150% of the raw) which in my case is huge (raw data is easily 200MBs+, and the multitude of projections can make it several 100's of MBs easily). There is the option of saving several files, but then it may become a nightmare for a user to 'transfer' files properly, so a one-file system seems best. I basically need to have the XML-like structure accessible to the UI, while the raw data needs to be accessed by the unmanaged code. So I was thinking I could concat

How to return back back to code behind file after cascading dropdown calling

Hi, I have a cascading dropdown. After the dropdown is populated(it is in another file)  i would like to return back to the original form where the control is placed. is there anyway of doing it

Calling WCF Services From Silverlight Keeping The Code Inline in VB.NET

Hello,   I have a large amount of code that I'm trying to convert to a Silverlight 4 Application from a VB.NET Win Forms App.  All of the business logic code is written inline calling stored procedures on a database.  There is so much code that it's overhelming to be making asynchronous call after asynchronous call back to the WCF service.  The code is now all over the place since I'm having to chain methods all around after the WCF calls complete.    I don't really need these WCF calls to be done synchronously (since we don't want to block the main UI thread), but is there any good way in VB.NET to keep all the code in-line when calling a WCF service?  Is there some sort of wrapper that can be used to call the WCF methods or another way?  I know some of this is done easier in C#, but I'm having some issues with this being done in VB.NET.   Example In The VB.NET App I'm Converting:   Dim Customer As New Customer   If Customer.CheckIfCustomerExists(10) = True    'Calls the database, checks if Customer #10 exists        'Do Something   Else       Dim CustomerNum As Integer = Customer.InsertNewCustomer("Customer Name")       'Do Something    End If In Silverlight This Woul

Calling Serverside PageMethod function from an external page Client Side Code ?

there is many examples on the net about this issue .like this :http://sappidireddy.wordpress.com/2008/03/31/how-to-call-server-side-function-from-client-side-code-using-pagemethods-in-aspnet-ajax/But all javascript codes are in same aspx file including codebehind WebMethodsI wantto call a pagemethod from a js which is in another page.something like this : (javascript code but not in same aspx)PageMethods("www.externalpage.com").GetContactName(ctrl.value, CallSuccess, CallFailed, dest)).or calling WebMethods from javascript must only be defined in codebehind with linked aspx fileonly avaible in same aspx ?cant I call a Webmethod in a.aspx from a javascript in b.aspx ?any clue ?thanks.

Unmanaged Code

What is the difference between UnManaged code & UnSafe code???? Explain with an example  please ???? 

JQuery Plugin: calling jConfirm from asp.net (code behind)

i am using jquery plugin and i got stuck in how to display the confirmation window from code behind and if the user choose "ok" than go ahead delete otherwise ignore. jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) { jAlert('Confirmed: ' + r, 'Confirmation Results'); }); anybody have done similar?  

Calling csharp code from Javascript

Hi, Is it possible to call a c# code block from Javascript in Sharepoint 2010? I am using redirects to pages at the moment to achieve the effect, but the results are far from desirable. Any help would be much appreciated.   Cheers, M

Checking the calling of JavaScript Code?


Hi Experts.

I am looking for the way to solve my problem. Suppose the following scenario:

You have a simple JavaScript code to connect with server and return some parameters form server and use it in your webpage. Like:

<script language="JavaScript">id=100</script> 

<script language="JavaScript" src="">           

The content of samplecode.js is like this:


                // code here.



When the script is run, some parameters are returned from server and is write into your page. Like: (document.write(parameters) ).

So now You want to use this script more than one time in your webpage. Then each time  is run separately and the parameters are returned in separately call. Like:

<script language="JavaScript">id=101</script> 

<script language="JavaScript" src="">

When the first JavaScript is called,  How can return the all parameters that is returned in separately JavaScript? Or Is there any the way to check to several times the javaScript is called in the page and when jus

change the PHP page with WCF service on Servers only, without chnging code on the calling client sid



I need to change the PHP page with WCF service, but the problem is that many of our clients are sending(usig POST) large stream data like binary files to our PHP website, now we are upgrading our system and moving towards wcf services,

The problem is that we want our clients to only change URL, and do not need to change any code in their calling mechanism or no need to create proxy on their cliend side. We simply change php to wcf services on our Servers only. Our clients are using .net 2.0 client application. Is there any way to do this. or Is this possible ?

One thing which I get from internet is use Rest based wcf services.

Have anybody some example or idea to accomplish my task.


Calling function from code behind


 I need help putting together code that would call the below Java function in asp vb 2008. Thank you.


<script type="JavaScript">
     function OnBeginRequest(sender, args)

No return from unmanaged code, methods to catch exception?


I am developing a c# application that needs to calls functions from a c header file. I use

[System.Runtime.InteropServices.DllImport("xxx.dll", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true,SetLastError=true)]
        public static extern Byte xxxx(IntPtr hResourceContext, ushort xxxx, ref structa aaa,ref Result_struct Result, Byte b);

to import the dll method. When I call this method in C#, the application simply exits without throwing an exception or error. I've used similar approach for other methods from the same dll which involves passing nested structs as parameter and they work fine. I would like to know how I can debug the code/ catch errors/exceptions from the unmanaged code.

I tried to include the SetLastError=true during DllImport but it does not help.


Calling Button,s onclick event in javascript code


 Hi Experts.

I have a Button control in webpage.

<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" OnClientClick="test()"/>

When i click on button, i want to check some conditions

calling a code behind method using xaml?


Is it possible to call a method in a XAML's code-behind through XAML itself? ie:

<Image Source="{Binding GetRandomImagePath}" />


public string GetRandomImagePath(...){////}


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend