I have spent the entire day googling for the info, found most of it, here are the two best sites with the needed info: http://www.asp.net/data-access/tutorials/creating-a-data-access-layer-cs[^] http://weblogs.asp.net/scottgu/archive/2006/01/15/435498.aspx[^]
Hrizip
Posts
-
Need example code for making an universal table editor... -
Need example code for making an universal table editor...I have just gotten my new assignment; which is to design an universal (generic) table editor in ASP.NET, that fetches data from SQL and is able to CRUD this data. I quess this is a well known area to most experienced ASP.NET developers (I have just started with ASP.NET) so I presume there are solid code examples "out there". I would be most thankful if someone provided a good solid example for the above mentioned. Thanks in advance.
-
I need to pass an array from VBScript to VB.Net COM .DLLIt is difficult to say at this point which framework we were using at that point, chances are we were using 3.5. We are still mostly using 3.5, only several machines have 4.0 installed. Thanks for the info on double bracketing, I remember going through hell and trying every possible thing to make this work, I havent commited to memory all those trials (and errors). Kinda not surprising that there is/was a bug in the framework itself, that would explain a great deal of things. The whole process of interoping with legacy apps is just horrible, making it work gulps down 80% of total time spent developing an app. Similar problems happen when you have to cross the managed/unmanaged barrier between apps, and between various C languages. I remember going thru hell trying to adapt c++ code to vb.net code across managed/unmanaged barrier. It also has problems marshalling various data types, and its also "trial and error" until you find the right combination.
-
I need to pass an array from VBScript to VB.Net COM .DLL3.5 and 2.0
-
I need to pass an array from VBScript to VB.Net COM .DLLDouble bracketing is not necessary, its just that I read *somewhere* that it does something, but at this point I dont remember what, and I remember that the thing works just fine with single bracketing. Heres a code snippet to play with; So, make a new project of type class library, make it com visible and interoperable Paste this
Imports System.IO
Imports System.Math
Imports System.Object
Imports System.Threading
Imports System.Runtime.InteropServices
Imports System.Reflection
Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices.RegistrationServices
Imports System.Xml
Imports System.Xml.XPathPublic Class Class1 ' Main Class, declared as *com interopable*, type of project : "type library", meaning it will need to be registered in windows, and type library will need to be exported
' you wlll need to make a batch file with the following commands in it, to check whether it has been introduced into the global assembly cache, browse your hard drive
' to windows/assembly and look for an entry named "Test", if it *is* listed there, then it will work.'regasm Test.dll 'regasm Test.dll /tlb:Test.dll 'regasm Test.dll /codebase /tlb:Test.dll 'gacutil /i Test.dll ' Put it into the folder where you already put test.dll, along with \*regasm.exe\* and \*gacutil.exe\* (obligatory) and then execute the bat file ' The type library is now registered and you can call its methods (the only working method is called "Method1") Public Shared RezultatiY ' vb.NET array to hold our data Public Function MethodNumber(ByRef numberz) ' Fetch the array of type integer or double (will be converted to double) RezultatiY = Nothing Dim Arrayzz() As Object Arrayzz = Nothing Arrayzz = numberz Dim NumberOfElements As Integer = UBound(numberz) - 1 ' We need to find the total number of elements ReDim RezultatiY(NumberOfElements) ' And then redimension our array to that number of elements For i As Integer = 0 To UBound(Arrayzz) - 1 Dim Temp As Double = CDbl(Arrayzz(i)) RezultatiY(i) = CDbl(Temp) My.Computer.FileSystem.WriteAllText("C:\\Temp\\TestingIntegersAndDoubles.txt", RezultatiY(i) & " " & i & " " & " " & RezultatiY(i).GetType.ToString & vbCrLf, True) Next End Function Public Function MethodString(ByRef Words) ' Fetch the array of type string RezultatiY = Nothing
-
Pinvoking a non WIN32 API under VB, cant get handle to printerIt (SDK example) crashes with no relevant error code even on "pure" windows XP SP2 machine which normally accesses the printer. I have (finally) been contacted by Zebra support, they have given me an email address, which unfortunately does not exist.
-
Pinvoking a non WIN32 API under VB, cant get handle to printerTheir SDK is from 2007, done in C, and their support people havent responded to my queries yet, I wont hold my breath ;) If we had known we would have gone with a different manufacturer.
-
Pinvoking a non WIN32 API under VB, cant get handle to printerUSB interface - tested, can print, can use windows driver, cant use my app, cant use SDK app Ethernet interface - tested, can print, can use win driver, cant use my app, cant use SDK app This was tested on both win 7 and win Vista, I also tried it on VMWARE windows XP SP2 but it crashed immidiately, but possible due to virtualization itself. Tomorrow I will try it on "pure" Windows XP, but I dont expect much.
-
Pinvoking a non WIN32 API under VB, cant get handle to printerNo idea why I implemented loadlibrary, when I started working on this project first I tried to translate c code to vb code practically line by line, loadlibrary was the first thing on the way. I didnt think it might wreak havoc when combined with pinvoking , I will be removing it to see what happens. I have already tried your solution - it didnt work. I always get hPrinter returned as "0". I simply cant get the printer to return a valid handle. There is no way of finding out whether the dll communicates with the printer, therefore I cannot figure out what this 0 I get returned means, does it mean that no printer was found or something else? With no way of knowing how (and if) the dll, in itself, communicates with the hardware, I cant troubleshoot this.
-
Pinvoking a non WIN32 API under VB, cant get handle to printerI have SDkit provided by Zebra company, which features some C examples (which produce the same error as my VB.net code), I have my own code done in VB.net, the Delphi code was done by someone else on the internet (I do not have this code) and he stumbled into an extremely similar (maybe even identical) problem as I did. My string (the name of the printer) is null terminated and I did try to pass that as LParray, safearray, char array and stringbuilder (same result = fail), one time I passed it as a pointer to the first character in the arrey (namely character "Z"), that time I didnt get the error code 63 nor 61 but the handle returned was still 0. It is possible that I need to find a way to marshal this null terminated char array by the way of not sending only the pointer to the first element in the array but to the entire segment of memory, I do not know how to do this. Even if I manage to do it, which I will certainly try to do, I might still get 0 as returned printer handle value. No matter what I do, the returned printer handle always is "0", I think the dll is not able to communicate to the hardware hence errors 61 and 63 (no data from printer), hence invalid printer handle.
-
Pinvoking a non WIN32 API under VB, cant get handle to printerAnd here is the SDK manual for those who may find it interesting, the same web page also hosts the entire SDK. http://support.online-dubai.com/embu/Zebra/ZEBRA%20CARD%20PRINTERS/Technical/PrinterSetup_v2.06.04/program%20files/Zebra%20Technologies/Zebra%20SDK/Zebra%20SDK%20Reference%20Manual/SDKReferenceManual.pdf
-
Pinvoking a non WIN32 API under VB, cant get handle to printerIn the meantime I also tried it without SetLastError and Charset.Auto, and I toyed around with byval/byref, nothing changed. I also did try it with printerType set to both zero and 330 , with same result. I have found someone with a similar problem, unfortuantely the said individual does his programming in delphi so I am still trying to understand what he said, heres the text: I am attempting to access a function in a C-style DLL, written in Microsoft Visual C++ version 6.0. The function is defined as follows: INT __stdcall ZBRGetHandle(LPHANDLE hPrinter, LPSTR pName, LPINT printerType, LPINT err) In my Delphi project, I prototype the function as: function ZBRGetHandle(var handle: THandle; var drvName: Array of Byte; var prnType: Integer; var err: Integer) : Integer; {$IFDEF WIN32} stdcall; {$ENDIF} external 'ZBRPrinter.dll' ; I have a wrapper function within a class that calls this function. The class method is defined as: function Open(var drvName: array of Byte; var errValue: Integer) : Integer; stdcall; I call it as: function TZBRPrinter.Open(var drvName: Array of Byte; var errValue: Integer) : Integer; stdcall; begin Result := ZBRGetHandle(_handle, drvName, _prnType, errValue); end; note: _handle & _prnType are defined within the class TZBRPrinter as: private _handle: THandle; // _handle to printer driver _prnType: Integer; I initialize both variables in the class constructor: constructor TZBRPrinter.Create; begin // Execute the parent (TObject) constructor first inherited; // Call the parent Create method // Now set defaults self._handle := 0; self._prnType := 100; end; errValue is set to -1 prior to the call to TZBRPrinter.Open. In an attempt to root-cause the problem, I used my delphi executable as the debugging application for my ZBRPrinter.dll project. When the ZBRGetHandle is called via the Delphi application, what I find is puzzling: With respect to ZBRGetHandle within the dll source code, I find that the 3rd parameter, LPINT printerType, is invalid, and the 4th parameter, LPINT err is set to 100. The first 2 parameters are correct. I have tried using a fixed array of bytes and chars as the second parameter, and a String, yet I find that I still encounter problems when passing all 4 parameters to this DLL function. I find that if the dll's second parameter only gets the first char of the string, then the 3rd parameter gets the value 100, and the 4th gets the value -1 as I intend. If t
-
Pinvoking a non WIN32 API under VB, cant get handle to printerI tried both; 1) nothing, 2) 330, 1) byval and 2) byref, same result in all cases.
-
Pinvoking a non WIN32 API under VB, cant get handle to printerI am having doubts that Zebra SDK dll doesnt communicate with the printer for some reason which I cannot discern as I did not make the dll itself. I have no option but to contact Zebra, although I wont hold my breath, software programming support is usually abysmal. ;(
-
Pinvoking a non WIN32 API under VB, cant get handle to printerStill getting 63 ZBR_ERROR_GETPRINTERDATA_ERROR The handle still = 0
-
Pinvoking a non WIN32 API under VB, cant get handle to printerIts just wierd, the function does return a new value (changes the value before it runs through the function) and sets it to "0" which cant be right. The error code states that no data could be received from the printer. The printer is an USB printer, and it is on, and it does indeed work (prints normally). Why does it return an invalid handle?
-
Pinvoking a non WIN32 API under VB, cant get handle to printerI have, I also tries it as safearray, LParray, char array and other stuff, same end result, no go.
-
Pinvoking a non WIN32 API under VB, cant get handle to printerLet us suppose that I am having problems marshalling a null terminated char array to the function I wish to call (GetHandle function as stated in the previous post(s)). I guess I should "reserve" a specific size memory (malloc or something), fill it with chars taken from the string, make sure its null terminated and then pass this memory by reference to the dll. Additionally I think the pointer points only to the first element of the char array, dont know how this will reflect on the problem at hand. I have no idea how to achieve the above mentioned ;) Any help? sample code?
-
Pinvoking a non WIN32 API under VB, cant get handle to printer.Net, Studio 2008 By studying the SDK example, I deduce that the entries for printer type and name are irrelevant as they havent used those as well (value = 0). I am getting the error code back as I should (61 or 63, error getting data from the printer) so it would seem that the pinvoke works at least partially, what I am still not getting is the proper handle for the printer itself.
-
Pinvoking a non WIN32 API under VB, cant get handle to printerI am having some problems getting a printer driver to work in Visual Basic. I am stuck at not being able to get a printer handle from the printer dll. This is what I got thus far;
Static dll_loaded As Boolean
If Not dll_loaded Then
Dim dll_handle = LoadLibrary("ZBRPrinter.dll")
If dll_handle = 0 Then
MsgBox("LoadLibrary failed")
Return
Else
dll_loaded = True
MsgBox("LoadLibrary success!")
End If
End If
Dim pName As StringBuilder = New StringBuilder("Zebra P330i USB Card Printer")
Dim hPrinter As IntPtr = 2
Dim printerType = 330
Dim err As Integer = 0Dim ret = ZBRGetHandle(hPrinter, pName, printerType, err) If err = 61 Then MsgBox("Unable to open handle to Zebra printer driver") End If
I am using the following pinvoke sig:
DllImport("ZBRPrinter.dll", SetLastError:=True, CharSet:=CharSet.Auto)> Public Shared Function ZBRGetHandle(ByRef hPrinter As IntPtr, ByVal pName As StringBuilder, ByRef printerType As Integer, ByRef err As Integer) As IntPtr
End FunctionI am getting the following data returned to me as I run this code; hprinter gets changed from 2 (test number) to 0 pname is the stringbuilder (also tried it as a string) printertype is 330 err is 61 It seems that I am getting "through" to the dll but I am unable to get a proper printer handle. This is what I got in Zebra SDK:
// Load the Zebra MIFARE SDK library HMODULE hModule = LoadLibrary(\_T("ZBRGPMF.dll")); if (hModule) { form1.StatusBox->Text = "The DLL has been successfully loaded."; } else { //StatusBox->Text = "Error loading Zebra SDK DLL."; return FALSE; } // Get the functions zsdkGetHandle = (ZBRGetHandle)GetProcAddress(hModule, "ZBRGetHandle");
HANDLE hPrinter = NULL;
INT printerType = NULL;
INT err = 0,
ret = 0;ret = getHandle(&hPrinter, "Zebra P330i USB Card Printer", &printerType, &err); ret = getPrinterStatus(&err);
And by running that example I do get a handle returned (its 0x000000) and the thing works. This is the typedef I got with the SDK:
typedef INT (CALLBACK *ZBRGetHandle)(LPHANDLE hPrinter, LPSTR pName, INT* printerType, LPINT err);
I am (quite obviously) new to adapting the code from C# to VB, I have managed to make several projects work (win32 API b