I need call a LoginUser API from MC++ dll, but when I try to call the I have
always the same exception:
"System.NullRef erenceException : Object reference not set to an instance of
an object.
at LogonUser(Strin g lpszUsername, String lpszDomain, String lpszPassword,
Int32 dwLogonType, Int32 dwLogonProvider , IntPtr phToken)"
Thanks in advance
---------------------------------
this is the sample code
//MyClass.h
#pragma once
#using <mscorlib.dll >
using namespace System;
using namespace System::Runtime ::InteropServic es;
namespace MyClassNameSpac e
{
[DllImport( S"advapi32.dll" ,CharSet=CharSe t::Auto, SetLastError=tr ue)]
extern bool LogonUser( String* lpszUsername, String* lpszDomain, String*
lpszPassword,
int dwLogonType, int dwLogonProvider , IntPtr phToken);
public __gc class MyClass
{
// TODO: Add your methods for this class here.
public:
MyClass()
{
};
public:
void Login()
{
try
{
String *strUsername = new String( "username") ;
String *strDomain = new String( "domain");
String *strPassword = new String( "password") ;
IntPtr ptr = IntPtr::Zero;
bool bRet = LogonUser( strUsername, strDomain, strPassword, 3, 0, ptr);
}
catch (Exception *e)
{
System::Diagnos tics::Debug::Wr iteLine( e);
}
};
};
}
//-------------TEST APPLICATION
//Form1.h
#pragma once
namespace test
{
using namespace System;
using namespace System::Compone ntModel;
using namespace System::Collect ions;
using namespace System::Windows ::Forms;
using namespace System::Data;
using namespace System::Drawing ;
using namespace MyClassNameSpac e;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change
the
/// 'Resource File Name' property for the managed resource
compiler tool
/// associated with all .resx files this class depends on.
Otherwise,
/// the designers will not be able to interact properly with
localized
/// resources associated with this form.
/// </summary>
public __gc class Form1 : public System::Windows ::Forms::Form
{
public:
Form1(void)
{
InitializeCompo nent();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispos e(disposing);
}
private: System::Windows ::Forms::Button * button1;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::Compone ntModel::Contai ner * components;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeCompo nent(void)
{
this->button1 = new System::Windows ::Forms::Button ();
this->SuspendLayout( );
//
// button1
//
this->button1->Location = System::Drawing ::Point(108, 92);
this->button1->Name = S"button1";
this->button1->TabIndex = 0;
this->button1->Text = S"button1";
this->button1->Click += new System::EventHa ndler(this, button1_Click);
//
// Form1
//
this->AutoScaleBaseS ize = System::Drawing ::Size(5, 13);
this->ClientSize = System::Drawing ::Size(292, 271);
this->Controls->Add(this->button1);
this->Name = S"Form1";
this->Text = S"Form1";
this->Load += new System::EventHa ndler(this, Form1_Load);
this->ResumeLayout(f alse);
}
private: System::Void button1_Click(S ystem::Object * sender,
System::EventAr gs * e)
{
MyClass *myclass = new MyClass();
myclass->Login();
}
private: System::Void Form1_Load(Syst em::Object * sender,
System::EventAr gs * e)
{
}
};
}
// Form1.cpp
#include "stdafx.h"
#include "Form1.h"
#include <windows.h>
using namespace test;
int APIENTRY _tWinMain(HINST ANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
System::Threadi ng::Thread::Cur rentThread->ApartmentSta te =
System::Threadi ng::ApartmentSt ate::STA;
Application::Ru n(new Form1());
return 0;
} 0 1868 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: pawel |
last post by:
Hi!
I have a .dll library, with some exported function, which looks something
like this:
extern "C" {
int exported_f (int (__cdecl *callback) (int a, int b)) ;
}
now, I want to invoke this function wihtin the managed code and supply my
managed delegate function poiter as callback. I use DllImport, we know how
|
by: Yoni Rabinovitch |
last post by:
Is it possible to invoke a C# delegate/event handler asynchronously,
from unmanaged C++ ?
I assume this requires a Managed C++ wrapper, which would call
BeginInvoke on the delegate ?
Is this correct, and if so, does anyone have an example ?
Thanks !!
|
by: Vinay |
last post by:
Hi ,
I am having server and client. Client is a test machine.
I want to invoke the application binary which resides on
server from client machine. The binary is created using
C#. Please note that I know the administrative password
for the server. Can some one help?
TIA,
Vinay
|
by: Don |
last post by:
I have a third party C++ DLL that I am trying to use from C#. The
specific function I am trying to use is declared in C++ as follows:
ladybugConvertToMultipleBGRU32(
LadybugContext context,
const LadybugImage* pimage,
unsigned char* arpszDestBuffers,
LadybugImageInfo* pImageInfo );
|
by: Duncan Mole |
last post by:
Hi,
This is probably an easy one but it iy first bit of p/invoke. I am trying to
use the following C struct in a call:
typedef struct
{
BYTE SRB_Cmd;
BYTE SRB_Status,
BYTE SRB_HaId;
| |
by: RickDee |
last post by:
Please help, anybody.
I am trying to write a program so that it can launch an exe file ( which is
also genereated in C# ) and then simulate the button clicking and invoke the
methods inside the exe. The button clicking part is working fine, but I just
cannot get the method call.
Here is my program snippet.
**************************************************************
|
by: stephan querengaesser |
last post by:
hi ng,
i try to invoke a webservice-method with an filter-object, that
contains value types. if i don´t want to filter the return value of
the method, i have to pass a new instance of the filter-object without
setting any properties. but the value type-properties can´t be null
and the filter is set to 0 (int) or false (bool).
therefore i did implement the propertySpecified-pattern like this:
|
by: Chris |
last post by:
We are using SQLite.net in an application but getting a bottleneck at
the data access layer (it has been profiled). This is clearly because
p/invoke takes 5 to 10 times longer than it does calling the function
straight from C/C++ code.
Is it possible to write a wrapper in Managed C++ that provides a managed
interface to the SQLite API, but still accesses the SQLite API directly
(without using p/invoke)?
Chris
|
by: andrewcw |
last post by:
Can someone suggest a way to get the functions to match - I am trying to get
file versions, etc info. But its still in unmanaged code as far as I can
find.
VGetFileVersionInfoSizeA' has unbalanced the stack. This is likely because
the managed PInvoke signature does not match the unmanaged target signature.
And should I be using by ref or out for those return values ?? Thanks
public class APICall
{// Private Declare Function...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |