|
|
|
try to write a webmethod written in C# which has to use a method imported from a dll written in C++.
public char[] stringa;
[DllImport(<dll_name>)]
public static extern int RPC_GetStringa( ref char[] stringatest);
[WebMethod]
public int RPC_GetStringaWs()
{
int j = -1;
stringa = new char[127];
try
{
j = RPC_GetStringa (ref stringa );
return j;
}
catch (Exception e)
{
return j;
}
}
on the other side (C++) RPC_GetStringa accepts just a array of 127 char.
It's doesn't work.. The exception is: "Can not marshal parameter #1: Ansi char arrays can not be marshaled as byref or as an unmanaged-to-managed parameter." }
Any suggestions will be very appreciated! Thanks in advance.
Paolo Leoncini
|
|
|
|
|
I'm using a ListBox without the scrollbar and I want to have a visual indicator to show that there is more item on the top or on the bottom of the ListBox.
For the top I use TopIndex, but for the bottom ? BottomIndex doesn't exist.
So, how to know the last visible index of a listbox ?
Thanks
|
|
|
|
|
I found a way with IndexFromPoint.
|
|
|
|
|
I'm using MAPI33 wrapper DLL in my C# program to read mails from Outlook/Exchange. I was using
the wrapper to avoid the popup messages thrown by the Outlook message guard and it almost workd
till I started reading attachments from a message. I was able to retreive attachment
size/number/name properites but was unable to open any of them. I'm facing problems with
IAttachment interface exposed by the wrapper.
This is how I'm trying to read attachments:
IAttachment tempAttach;
hr = msg.OpenAttach(intAttachNum,Guid.Empty,
__MAPI33__INTERNALS__.Message.FLAGS.DeferredErrors,
out tempAttach);
Above code gives a pointer to the Attachment object.
MAPI33.IUnknown stmUnKNown;
hr = tempAttach.OpenProperty(Tags.PR_ATTACH_DATA_BIN,
Guid.Empty,0,
__MAPI33__INTERNALS__.MAPIProp.FLAGS.DeferredErrors,
out stmUnKNown);
Above code is giving two types of errors depending on the Flag property i.e., for some I'm
getting "Invalid Property" and for others "Errors Returned."
Pls point me to any examples or additional information.
|
|
|
|
|
I have a client application that successfully uses a singleton remote object hosted on a seperate server. Recently I have changed the same client application to also use a second singlecall remote object. The two objects are exposed through two seperate channels. During develpment the singlecall object was on the same machine as the client application.
I mannged to get this working but when I move the new object to another machine it no longer works. All I get is an internal error message on the client saying to turn customErrors on in the server. However doing so chnages nothing.
Any ideas where I'm going wrong?
|
|
|
|
|
Maybe it's got something to do with the machine's CAS policy? Did you try setting the TypeFilterLevel to full?
Regards
Senthil
|
|
|
|
|
I am Logon user to create the impresonate user. When the run the code on windows 2000 I am getting the message "A required privilege is not held by the client."
Can any one let me know what privalages has to set.
For reference I am attaching the code also.
[assembly:SecurityPermissionAttribute(SecurityAction.RequestOptional, UnmanagedCode=true)]
[assembly:PermissionSetAttribute(SecurityAction.RequestOptional, Name = "FullTrust")]
[DllImport("advapi32.dll", SetLastError=true)]
public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword,
int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
[DllImport("kernel32.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
private unsafe static extern int FormatMessage(int dwFlags, ref IntPtr lpSource,
int dwMessageId, int dwLanguageId, ref String lpBuffer, int nSize, IntPtr *Arguments);
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public extern static bool CloseHandle(IntPtr handle);
[DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public extern static bool DuplicateToken(IntPtr ExistingTokenHandle,
int SECURITY_IMPERSONATION_LEVEL, ref IntPtr DuplicateTokenHandle);
public unsafe static string GetErrorMessage(int errorCode)
{
int FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
int FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;
int FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000;
//int errorCode = 0x5; //ERROR_ACCESS_DENIED
//throw new System.ComponentModel.Win32Exception(errorCode);
int messageSize = 255;
String lpMsgBuf = "";
int dwFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
IntPtr ptrlpSource = IntPtr.Zero;
IntPtr prtArguments = IntPtr.Zero;
int retVal = FormatMessage(dwFlags, ref ptrlpSource, errorCode, 0, ref lpMsgBuf, messageSize, &prtArguments);
if (0 == retVal)
{
throw new Exception("Failed to format message for error code " + errorCode + ". ");
}
return lpMsgBuf;
}
string userName;
userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
MessageBox.Show(userName);
IntPtr tokenHandle = new IntPtr(0);
IntPtr dupeTokenHandle = new IntPtr(0);
tokenHandle = IntPtr.Zero;
dupeTokenHandle = IntPtr.Zero;
const int LOGON32_PROVIDER_DEFAULT = 0;
const int LOGON32_LOGON_INTERACTIVE = 2;
bool returnValue = LogonUser(textBox1.Text, textBox2.Text, textBox3.Text,
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,
ref tokenHandle);
somebody please help me
|
|
|
|
|
From the documentation[^]:
Windows 2000: The process calling LogonUser requires the SE_TCB_NAME privilege. If the calling process does not have this privilege, LogonUser fails and GetLastError returns ERROR_PRIVILEGE_NOT_HELD. In some cases, the process that calls LogonUser must also have the SE_CHANGE_NOTIFY_NAME privilege enabled; otherwise, LogonUser fails and GetLastError returns ERROR_ACCESS_DENIED. This privilege is not required for the local system account or accounts that are members of the administrators group. By default, SE_CHANGE_NOTIFY_NAME is enabled for all users, but some administrators may disable it for everyone.
SE_TCB_NAME is known as "Act as part of the operating system" in the privilege-setting user interface. It's only given to the SYSTEM/LocalSystem account by default.
Since you don't say what you're trying to do, it's difficult to help further. If you want to create a process running under a different user account, try CreateProcessWithLogonW[^].
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Thanks Mike,
This is the first time I am working on the windows security can you please let me where to set the SE_TCB_NAME and SE_CHANGE_NOTIFY_NAME privalage.
I need the User name, Password and the Domian name to provide it for a windows services developed by me. I am using "this accont" option in the properties dialog of the service manager as I have to access few protected resource on the system.
While installing the service in the for the first time I need to give these deatils. So I have UI which will query for the User name and the password then I would want to validate the user name and password before mounting and starting the service.
My initial idea was to use logon user function, if it succeeds then the credential entered are correct and I can continue to start the service.
Is there any other alternate method of doing this. Please help me
thanks and regards
Sharath
|
|
|
|
|
sharathgowda wrote:
This is the first time I am working on the windows security can you please let me where to set the SE_TCB_NAME and SE_CHANGE_NOTIFY_NAME privalage.
That's why you need to read the documentation he linked. Those privileges are granted to users through the security configuration of the machine or domain (which applies to the machine). It's all covered in linked documentation from the documentation you were given.
You do not need to use LogonUser to prompt for the username and password, however. You only need the credentials. If you want to authenticate that the credentials are correct than calling LogonUser is by far the easiest way to authenticate them.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello...
I have some problems with my tabcontrol. I would like to make it transparent, but I cant....is there any way to make the tabpages AND the tabs transparent? If there is a way to do this, please help me..
//Carnilmo
|
|
|
|
|
Hi all,
Are there any good third-parties UI control components for .NET ?
I want to use them to re-decorate the view design of my project.
Thanks
|
|
|
|
|
|
Hi all,
My project need a MAPI component for those mapi and smtp encode
and decode. Do anyone know any good third-parties components on it which I
can called the component by C# ?
Thanks
|
|
|
|
|
hi all,
I am doing a C# Application.
I want to add check Boxes to Extra Column in a DataGrid..Other thing is when check Box Click I need to do some oprations..
("suppose that when I click check box in a DataGrid Column, I need to popup Message")
How do I do this?
please any one know this please help me.
Thanks in advance
|
|
|
|
|
I reckon the reason no-one is answering is that this question is well answered in CP articles, and elsewhere on the web.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Hi all
how can I write programe in C# to get thw URL from the address bar when any one use the internet explorer .
Please help me.
Thanks.
|
|
|
|
|
You might want to explain why you want this first...people on here aren't too interested in helping with spyware applications...just in case that's what you had in mind.
|
|
|
|
|
If you're hosting the WebBrowser control in your Windows Forms application, get the LocationURL property. If you want to get the URL from a running instance of Internet Explorer, you can use the InternetExplorerClass from shdocvw.dll by creating an RCW (Runtime Callable Wrapper, or "interop assembly") like so:
tlbimp /out:Interop.SHDocVw.dll %windir%\system32\shdocvw.dll You can also create this in VS.NET by adding a reference to your project, click on the COM tab, and find "Microsoft Internet Controls". You can then do something like this:
InternetExplorerClass ie = new InternetExplorerClass();
return ie.LocationURL; There are rules regarding this property and what can retrieve the value, so you should read about it in the MSDN Library[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I write in my programe :
InternetExplorerClass ie = new InternetExplorerClass();
textBox1.Text = ie.LocationURL;
but when i excute it , it gives empty string not url ,what is the wrong???
|
|
|
|
|
I told you - you need to read the documentation for the property: it is protected for the very same reasons that the other reply mentioned - to prevent malware from gather information about your browsing habits out of process. There is more information about what is and isn't possible at http://msdn.microsoft.com/library[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I'm putting together a project and need to extend Windows' shell to add a owner-drawn menu item to the context menu. If I use only IContextMenu, the menu item and owner-drawn (blank) sub menu are added fine.
As soon as I implement IContextMenu2 and HandleMenuMsg, I get a memfault from Explorer whilst debugging. A breakpoint is hit inside the IContextMenu2.HandleMenuMsg but subsequently, Explorer crashes. I'm returning "0" from int HandleMenuMsg(uint, IntPtr, IntPtr).
Any ideas?
--------------------------------
Extension code:
[ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), GuidAttribute("000214e8-0000-0000-c000-000000000046")]
public interface IShellExtInit {
[PreserveSig()]
int Initialize (IntPtr pidlFolder, IntPtr lpdobj, uint /*HKEY*/ hKeyProgID);
}
[ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), GuidAttribute("000214e4-0000-0000-c000-000000000046")]
public interface IContextMenu {
[PreserveSig()]
int QueryContextMenu(HMenu hmenu, int iMenu, int idCmdFirst, int idCmdLast, CMF uFlags);
[PreserveSig()]
void InvokeCommand(IntPtr pici);
[PreserveSig()]
void GetCommandString(int idcmd, uint uflags, int reserved, StringBuilder commandstring, int cch);
}
[ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), GuidAttribute("000214e4-0000-0000-c000-000000000046")]
public interface IContextMenu2 : IContextMenu {
[PreserveSig()]
int HandleMenuMsg(uint Msg, IntPtr LParam, IntPtr WParam);
[PreserveSig()]
new int QueryContextMenu(HMenu hmenu, int iMenu, int idCmdFirst, int idCmdLast, CMF uFlags);
[PreserveSig()]
new void InvokeCommand(IntPtr pici);
[PreserveSig()]
new void GetCommandString(int idcmd, uint uflags, int reserved, StringBuilder commandstring, int cch);
}
--------------------------------
Shell code:
public int QueryContextMenu(HMenu hmenu, int iMenu, int idCmdFirst, int idCmdLast, CMF uFlags) {
//
HMenu AppMenu;
Int32 NewMenuID = 1;
// Check Flags
if ((uFlags & (CMF.CMF_VERBSONLY|CMF.CMF_DEFAULTONLY|CMF.CMF_NOVERBS)) == 0 ||
(uFlags & CMF.CMF_EXPLORE) != 0) {
//
// Create Popup Menu
AppMenu = Helpers.CreatePopupMenu();
// Append SubMenus
Helpers.AppendMenu(AppMenu, MFMENU.MF_OWNERDRAW|MFMENU.MF_ENABLED,
new IntPtr(idCmdFirst + NewMenuID++), null);
Helpers.InsertMenu(hmenu, 3, MFMENU.MF_BYPOSITION|MFMENU.MF_POPUP|MFMENU.MF_ENABLED, AppMenu.handle, "MediaExplorer");
}
return NewMenuID;
}
#region IContextMenu2 Members
public int HandleMenuMsg(uint Msg, IntPtr LParam, IntPtr WParam) {
//
return 0;
}
#endregion
--------------------------------
>
|
|
|
|
|
I don't think you need the redefinitions of IContextMenu methods in there, they may be causing your the problem when it tries to marshal the interface. Even if your interface inherits another interface, in this case IContextMenu2 : IContextMenu, you don't redefine the members from the original interface.
Also, if i remember correctly, there is an entry on Raymod Kim's blog as well an anecdotal evidence that IContextMenu2 isn't very useful. The system checks for IContextMenu2 and if present then tries to use IContextMenu3, if that isn't present it falls back to the original IContextMenu. So you will need to implement the 3 interface for it to work i think.
I think your definitions of IContextMeuu are wrong as well. PreserveSig is used to prevent the signiture being changed because typically COM methods will return an HResult value. Your methods aren't returning HResult (or int) values and yet you've marked them with PreserveSig. Either remove the attribute or change the function definitions to match the definitions found in the header files exactly, otherwise i think you're either hiding errors or causing deeper problems which may not be apparent until the shell dies on you.
|
|
|
|
|