473,406 Members | 2,336 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.

Marshalling from C++ DLL to CSharp for const wchar_t * using Visual Studio 2008 SP1

Dear All,

I am stuck on these C++ data types const wchar_t * since last week.

It worked well in C# console application under mentioned below
Expand|Select|Wrap|Line Numbers
  1.  unsafe static void Main(string[] args)
  2. {
  3.   IntPtr ld, data1, data2;
  4.   string str = "test.txt";
  5.   int UTF_8 = 1;
  6.  
  7.   // Using PInvoke 
  8. [System.Runtime.InteropServices.DllImportAttribute("Test.dll", EntryPoint = "LoadFromFile")]
  9. public static extern System.IntPtr LoadFromFile(System.IntPtr aObj, System.IntPtr ex, [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPWStr)] string aPath, int aWritable);
  10.  
  11. [System.Runtime.InteropServices.DllImportAttribute("Test.dll", EntryPoint = "LoadFromFile_cset")]
  12. public static extern System.IntPtr LoadFromFile_cset(System.IntPtr aObj, System.IntPtr ex, int aEncoding, [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string aPath, int aWritable);
  13.  
  14.   // data1 and data2 should have some address
  15.   // get some address in console application heredata1 = LoadFromFile(ld, IntPtr.Zero, str, 1);
  16. data2 = LoadFromFile_cset(ld, IntPtr.Zero, UTF_8, str, 1);
  17.  
  18.   // but I got can't get any address in C# Window Form
  19.  
  20. }
Here is origina C++ functions
Expand|Select|Wrap|Line Numbers
  1.  struct Doc *API LoadFromFile (struct Loader *  aObj, struct Exception *  ex, const wchar_t *  aPath, int  aWritable) 
  2.  
  3. struct Doc *API LoadFromFile_cset (struct Loader * aObj, struct Exception *     ex, int     aEncoding, const char * aPath, int aWritable) 
So far I knew Marshalling or PInvoke used in anywhere console or window form, the result should be the same.

But very strange for this time since I am using other party libraries so I couldn't debug inside.

I hope some one will advise me since I need to close the case by tomorrow.


Thanks and best regards
Nov 18 '12 #1
0 1414

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Dutt | last post by:
AMD x86/x64 and Multi Core using Visual Studio 2008 http://msdotnetsupport.blogspot.com/2008/01/amd-x86x64-multi-core-visual-studio.html
0
by: madasamonkey | last post by:
I'm using Visual Studio 2008. The o/s is Win XP Pro. Here's my problem: The machine I'm working on is a PC and the monitor resolution is 1280 x 1024 The target machine on which the app will run...
4
by: Colin J. Williams | last post by:
The readme.txt has: All you need to do is open the workspace "pcbuild.sln" in Visual Studio, select the desired combination of configuration and platform and eventually build the solution....
3
by: hocking | last post by:
Hi,everyone ! I am using Emacs to edit source code ,i want to know how to compile code by using visual studio 2008 in emacs.
0
by: Fakher Halim | last post by:
Does someone know any place to get working examples of inherence implemented in Entity Framework using Visual Studio 2008 SP1. I could only implement just one table per hierarchy (...
4
by: kilabyte | last post by:
Hi, First post on here, I can't see that the question has been asked before. I am new to Visual Studio 2008 (using VB), but a seasoned programmer using Access and VBA. I have created a web...
3
by: Ashish101 | last post by:
Hi, I am developing a Windows application and I want to add controls (Textbox,ComboBox etc) to the grid using visual studio 2008 As we use ItemTemplates in grid in Web Application , I am...
1
by: StrykerNet | last post by:
My Crystal Report is pulling information from a stored procedure I wrote. So everytime I run my application it prompts me for a password for the server. How do I bypass this step and hardcode the...
1
by: mfaisalwarraich | last post by:
Hi Everybody, I am new to VB.NET. I have googled around for the connection string to connect with Sql Compact edition database. but i really have no idea how to do that. furthermore i dont know...
5
Ewan
by: Ewan | last post by:
Hi Im using Visual Studio 2008 and i have created a GridView which displays data from an SQL Table. Could anyone help me on how could i export this data into an Excel sheet on click of a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.