473,404 Members | 2,137 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,404 software developers and data experts.

Need help translating a C++ method to C#

2
I'm trying to use a method defined in the Windows Media Format SDK (wmsdkidl.h)
Expand|Select|Wrap|Line Numbers
  1. virtual HRESULT STDMETHODCALLTYPE AcquireCredentials( 
  2.             /* [in] */ WCHAR *pwszRealm,
  3.             /* [in] */ WCHAR *pwszSite,
  4.             /* [size_is][out] */ WCHAR *pwszUser,
  5.             /* [in] */ DWORD cchUser,
  6.             /* [size_is][out] */ WCHAR *pwszPassword,
  7.             /* [in] */ DWORD cchPassword,
  8.             /* [in] */ HRESULT hrStatus,
  9.             /* [out] */ DWORD *pdwFlags) = 0;
In C++ I have some sample code that actually implements this and it's working
Expand|Select|Wrap|Line Numbers
  1. HRESULT CNetWrite::AcquireCredentials( WCHAR *pwszRealm, 
  2.                                       WCHAR *pwszSite, 
  3.                                       WCHAR *pwszUser, 
  4.                                       DWORD cchUser, 
  5.                                       WCHAR *pwszPassword, 
  6.                                       DWORD cchPassword, 
  7.                                       HRESULT hrStatus, 
  8.                                       DWORD *pdwFlags )
  9. {
  10.     HRESULT hr = S_OK;
  11.  
  12.     WCHAR *wszUser     = NULL;
  13.     WCHAR *wszPassword = NULL;
  14.  
  15.     hr = ConvertTCharToWChar2( "MyUsername", &wszUser );
  16.     hr = ConvertTCharToWChar2( "MyPassword", &wszPassword );
  17.  
  18.     wcscpy(pwszUser, wszUser);
  19.     wcscpy(pwszPassword, wszPassword);
  20.  
  21.     (*pdwFlags) = 0x00;
  22.  
  23.     SAFE_ARRAYDELETE( wszUser ); 
  24.     SAFE_ARRAYDELETE( wszPassword );
  25.  
  26.     return S_OK;
  27. }
But I cannot get it to work in C#. Until now, I have the following definition
Expand|Select|Wrap|Line Numbers
  1. [ComImport]
  2. [Guid("342e0eb7-e651-450c-975b-2ace2c90c48e")]
  3. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
  4. public interface IWMCredentialCallback
  5. {
  6.   void AcquireCredentials(
  7.     [In, MarshalAs(UnmanagedType.LPWStr)] string bstrRealm,
  8.     [In, MarshalAs(UnmanagedType.LPWStr)] string bstrSite,
  9.     [In, Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pwszUser,
  10.     [In] uint cchUser,
  11.     [In, Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pwszPassword,
  12.     [In] uint cchPassword,
  13.     [In] IntPtr hrStatus,
  14.     [In, Out] uint pdwFlags);
  15. }
with the following implementation
Expand|Select|Wrap|Line Numbers
  1. public void AcquireCredentials(string bstrRealm, string bstrSite, StringBuilder pwszUser, uint cchUser, StringBuilder pwszPassword, uint cchPassword, IntPtr hrStatus, uint pdwFlags)
  2. {
  3.   pwszUser     = new StringBuilder("MyUsername");
  4.   pwszPassword = new StringBuilder("MyPassword");
  5.  
  6.   pdwFlags = 0x00;
  7. }
Can somebody help me make this method work in C#?
Apr 17 '07 #1
0 838

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

Similar topics

3
by: Gabe Covert | last post by:
I'm a new C# developer, and am developing an application which will utilize a COM library from a third party. I have two following SDK calls from the 3rd-party SDK which I can't get to work under...
3
by: Eirik Eldorsen | last post by:
I'm tring to translate an VB.NET method into C#. Here is what I've done so far. Need help on the while loop public static void SetInitialFocus(Control ctrl) { StringBuilder s = new...
6
by: Patrick Sullivan | last post by:
I want to use this algorithm but can't figure it out, I never used BASIC. I tried translating it but got lost in the gosubs and "for i - 1 to ... nexts". I have figured out that FNU(X) is degree...
0
by: kboek | last post by:
I'm trying to use a method defined in the Windows Media Format SDK (wmsdkidl.h)virtual HRESULT STDMETHODCALLTYPE AcquireCredentials( /* */ WCHAR *pwszRealm, /* */ WCHAR...
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
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
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,...
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.