473,769 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help:System.Nul lReferenceExcep tion with unmanaged memcpy

noe
I have done a DLL in unmanaged code C++ and in that dll I have defined
a function that use memcpy.This dll run ok.I use that dll in a
aplication in C# managed code in Visual Studio .NET. I import the
functions defined in the dll using DllImport and I have verified that
when in my dll I use memcpy then I have one error
:"System.NullRe ferenceExceptio n", and I don't known what happen?and I
must use memcpy in my dll.
Below is the definition of function in my DLL "DllWin32":
-------------------------------------------------------
DllExport bool Conectar()
{

HANDLE hAndle_ndisprot ocol;
hAndle_ndisprot ocol = CreateFile("\\\ \.\\\\miprotoco ldriverNDIS",
GENERIC_READ|GE NERIC_WRITE,
FILE_SHARE_READ |FILE_SHARE_WRI TE,//share for reading and
writing
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_ NORMAL,
(HANDLE) INVALID_HANDLE_ VALUE);
dwErr = GetLastError();
//*************** ****
if (dwErr!=0)
{
FormatMessage(F ORMAT_MESSAGE_A LLOCATE_BUFFER
|FORMAT_MESSAGE _FROM_SYSTEM |FORMAT_MESSAGE _IGNORE_INSERTS ,
NULL,
dwErr,
MAKELANGID(LANG _NEUTRAL, SUBLANG_DEFAULT ),
(LPTSTR)&buff,
0,
NULL);
//Display the string
MessageBox(NULL ,(LPTSTR)buff," Device.Error de
CreateFile",MB_ ICONWARNING);
//Free the buffer
LocalFree(buff) ;
}
//*************** ****
//Bind the file handle to the driver
bl=DeviceIoCont rol(hAndle_ndis protocol,
IOCTL_NDISPROT_ BIND_WAIT,
NULL,
0,
NULL,
0,
&dwReturned,
NULL);
dwErr = GetLastError();
//*************** ****
if (dwErr!=0)
{
FormatMessage(F ORMAT_MESSAGE_A LLOCATE_BUFFER
|FORMAT_MESSAGE _FROM_SYSTEM |FORMAT_MESSAGE _IGNORE_INSERTS ,
NULL,
dwErr,
MAKELANGID(LANG _NEUTRAL, SUBLANG_DEFAULT ),
(LPTSTR)&buff,
0,
NULL);
//Display the string
MessageBox(NULL ,(LPTSTR)buff," Device. Error llamada
IOCTL_NDISPROT_ BIND_WAIT",MB_I CONWARNING);
//Free the buffer
LocalFree(buff) ;
}
//*************** ****
WCHAR *pwDeviceName;
CHAR Buf[1024];
PNDISPROT_QUERY _BINDING pQueryBinding;
pQueryBinding = (PNDISPROT_QUER Y_BINDING)Buf;

bl = DeviceIoControl (hAndle_ndispro tocol,
IOCTL_NDISPROT_ QUERY_BINDING,
pQueryBinding,s izeof(NDISPROT_ QUERY_BINDING),
Buf, 1024,
&dwReturned,
NULL);
dwErr = GetLastError();
//*************** ****
if (dwErr!=0)
{
FormatMessage(F ORMAT_MESSAGE_A LLOCATE_BUFFER
|FORMAT_MESSAGE _FROM_SYSTEM |FORMAT_MESSAGE _IGNORE_INSERTS ,
NULL,
dwErr,
MAKELANGID(LANG _NEUTRAL, SUBLANG_DEFAULT ),
(LPTSTR)&buff,
0,
NULL);
//Display the string
MessageBox(NULL ,(LPTSTR)buff," Device. Error llamada
IOCTL_NDISPROT_ QUERY_BINDING", MB_ICONWARNING) ;
//Free the buffer
LocalFree(buff) ;
}
//*************** ****
//Convierto el nombre del dispositivo en un string Unicode(caracte res
anchos de 16 bits)
pwDeviceName=(W CHAR*)malloc(pQ ueryBinding->DeviceNameLeng th);

memcpy(pwDevice Name,((PBYTE)pQ ueryBinding+pQu eryBinding->DeviceNameOffs et),pQueryBindi ng->DeviceNameLeng th);

return true;
}

---------------------------------------
My application in C# in Visual studio .NET:
------------------------------------
[STAThread]
static void Main()
{
bool ok;
Application.Run (new Form1());
ok=ApiWin32.Con ectar();//Here is the error
System.NullRefe renceException
if (ok)
{
ApiWin32.Messag eBox(0,"Funcion a","Ejemplo de invocación de
plataforma",0);
}
else
{
ApiWin32.Messag eBox(0,"No funciona","Ejem plo de invocación de
plataforma",0);
}

}
-------------------------------------

ApiWin32 is class that I have defined:
------------------------------------
public class ApiWin32
{
[DllImport("user 32.dll", CharSet=CharSet .Auto)]
public static extern int MessageBox ( int hWnd,
String lpText,
String lpCaption,
uint uType) ;

[DllImport("DllW in32.dll", CharSet=CharSet .Auto)]
public static extern bool Conectar () ;
//Constructor de la clase
public ApiWin32()
{

}
}
-----------------------------
Please help me, I don't Known what happen.

Nov 17 '05 #1
0 2137

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2034
by: Tim21 | last post by:
OK, im miserable :)) so.. help'd b highly appreciated. Situation: Win XP aplication server RUNTIME (stored fmx files along with the ..hlp files) Fmx's generated and compiled on development machine (Win2003 Advanced Server), also place of generation of HLP files (using HCW-Help Workshop Compiler)) Problem: When trying to call help file from module (fmx) (ON runtime machine) by pressing F1 (help key),. system seems not to react at all....
5
1764
by: dixie | last post by:
I was wondering if there is a way of doing a simple help system with either viewing a page in a browser or looking at a definite page in a .pdf file when a help button was pushed on an Access application form. I understand there are other ways of doing help files, but are these possible, what is the easiest and how much work is it? dixie
3
1132
by: Jay | last post by:
Well just installed the new 7.1 compiler. Not bad I must say but I'm becoming increasingly frustrated with the help system. Problem: project didn't compile due to DX9 include directories not being found (guess this is really a bug in the settings conversion from 7.0 albeit a minor one) Couldn't find where to set the include and library directories so went to the help system and typed 'include directories tools options'.
5
3382
by: Steve Teeples | last post by:
Can someone point me to a document that clearly identifies the steps of creating a good help system for an application? I have a test tool that I'd like to add help to so that others will know how to use it. -- Steve
9
2248
by: JJ | last post by:
Do you all use HTML help workshop to create your help system. I am finding it quite clumsy to use. Mayeb because I am not used to using it. Do any of you use any other techniques to create help for your progs? Whats the current popular approach to creating help? I am only wanting a straight help file accessible from a menu - no context sensitive stuff. TIA
3
1500
by: firewood | last post by:
I am developing a CMS/web-building website, and I need to include a good help system to help my customers learn how to use the features of what my project offers. Does anyone have suggestions about what help products I could incorporate into my site? I want the standard outline system, with a column showing chapters, an index, and search box. Any leads will be greatly appreciated.
8
1691
by: redefined.horizons | last post by:
I did some searching for this topic, but couldn't find anything. A search of this list only turned up an old post from 2002. I'd like to add a comprehesive help system to my Python Application. By "comprehensive" I mean regular "read-like-a-book" help and context sensitive help that can be launched from the application. Is there an existing system in Python that would support this, or would I need to start from scratch?
2
1428
by: Mark Thompson | last post by:
Hi, I have a VB.NET 2003 application which includes a help system developed externally into a .chm file which is linked to from the application. There are 3 ways the application links to the help: 1) Via a menu which just executes the help system using Help.ShowHelp with the specified URL for the introduction page 2) Via a keyboard shortcut that executes the help system using Help.ShowHelp with the specified URL.
6
4031
by: JonathanOrlev | last post by:
Hello everyone, I have a newbe question: In Access (2003) VBA, what is the difference between a Module and a Class Module in the VBA development environment? If I remember correctly, new types of objects (classes) can only be defined in Class modules.
10
3364
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably the worst I ever seen. I almost cannot find anything I need, including things I
0
9579
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, 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...
0
9422
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10208
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9987
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,...
0
8867
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7404
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
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();...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
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 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.