473,396 Members | 1,772 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,396 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 18 '07 #1
0 1300

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

Similar topics

6
by: Davis Marques | last post by:
hi; I'm translating some PHP scripts to Python and have hit a roadblock with a for statement. If someone could explain to me how one should translate the multiple increment, evaluations, etc....
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...
9
by: Hugo Amselschlag | last post by:
Hi there, I've implemented a local system hook to suppress certain windows beeing displayed by the axWebbrowser control. Now I need some more information before I can decide, whether to suppress...
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...
9
by: Daniel Gee | last post by:
A while ago I wrote a class in Java for all kinds of dice rolling methods, as many sides as you want, as many dice as you want, only count values above or below some number in the total, things...
1
by: timn | last post by:
Translating Access SQL queries into SQL subqueries. -------------------------------------------------------------------------------- I have a query in Access that uses a subquery, I would like...
4
by: koren99 | last post by:
Hi, I am having problems creating a good model for this. and i'll appriciate any help. Req. 1. parse a predefind language such as arethmatic: 4+5-7*9... with abilty to extend / add more...
1
by: trihaitran | last post by:
Hi I am new to Ruby from Python and am still learning some stuff. I have a Ruby program that uses the mechanize library to connect to a Web site and authenticate with a username and password. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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,...

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.