• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3111
  • Last Modified:

How register dll (internal) in Visual Studio 2008/2010 in Visual Basic page (.aspx/.vb)

How i can register a dll located in bin section of a Visual Studio Solution without register the dll in a PC?
When i register a gsdll32.dll in a PC, their usage in one page (developet in Visual Basic) is correctly if i import the dll into a page but...
If i heve the some dll in a bin section but not register the dll in a PC thats dont run.

{"Unable to load DLL 'gsdll32.dll': No se puede encontrar el módulo especificado. (Exception from HRESULT: 0x8007007E)"}

Some solution? Thanks
1 Solution
StephanLead Software EngineerCommented:
Did you add it as reference?
77258840Author Commented:
When I try to add the reference from Bin I get the following message:
A reference to: "C:\Users\Usuario\Documents\Visual Studio 2010\WebSites\MafWeb\Bin\gsdll32.dll" could not be added. No type libraries were found in the component.
In Bin i have too gsdll32.lib.
In another PC did all the tests imaginable and until ghostscript registered on the PC I could not add the reference.
I need the dll into the solution because, when i sent the application to Serevr, I can not install ghoscript in the Server because I may not.
use p/invoke
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Mohamed OsamaSenior IT ConsultantCommented:
Do you intend to create a setup package to install your application on the server or is the installation manual / script based ?
I am not sure why installing Ghostscript on the server is an issue, a Program prerequisite installation like GS should not be an issue for the system admin / security admin 
if no Setup project is planned ,you can also add a one liner script to xcopy the DLL in your Application path.

77258840Author Commented:

I WANT TO USE THIS SAMPLE FROM http://www.codeproject.com/KB/cs/GhostScriptUseWithCSharp.aspx?msg=3125329 
but my application is buid in Visual Studio 2010 in Visual Basic codebehind.

which is the way to do this in VB? (especially[DllImport("gsdll32.dll... ).  

/// <summary>Create a new instance of Ghostscript.</summary>
/// <param name="pinstance"></param>
/// <param name="caller_handle"></param>
/// <returns>The instance passed to other GS function</returns>
[DllImport("gsdll32.dll", EntryPoint="gsapi_new_instance")]
private static extern int gsapi_new_instance (out IntPtr pinstance,
    IntPtr caller_handle);

/// <summary>This will make the conversion</summary>
/// <param name="instance"></param><param name="argc"></param><param name="argv"></param>
/// <returns>0 if is ok</returns>
[DllImport("gsdll32.dll", EntryPoint="gsapi_init_with_args")]
private static extern int gsapi_init_with_args (IntPtr instance, int argc, IntPtr argv);
/// <summary>Exit the interpreter</summary>
/// <param name="instance"></param><returns></returns>
[DllImport("gsdll32.dll", EntryPoint="gsapi_exit")]
private static extern int gsapi_exit (IntPtr instance);

/// <summary>Destroy an instance of Ghostscript.</summary>
/// <param name="instance"></param>
[DllImport("gsdll32.dll", EntryPoint="gsapi_delete_instance")]
private static extern void gsapi_delete_instance (IntPtr instance);


to convert your snippet to vb.net online
ah, and add

Import System.Runtime.InteropServices

77258840Author Commented:
Thank you to all but I have found the solution on my own.
For have all resources from a gsdll32.dll is necesary to put

Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal DllInternalPath As String) As Long
Public Declare Function gsapi_new_instance Lib "gsdll32.dll" (ByRef lngGSInstance As IntPtr, ByVal lngCallerHandle As IntPtr) As Integer
and other needed declarations...
in the Class declarations.

and after, before the use of dll, in anywhere in the code
        Dim DllInternalPath as String = "xxxxxxxxxxxxxxxxxxxx", Largo As Long = LoadLibrary("DllInternalPath")

with this when you use the needed declarations of gsdll32.dll like (for example)
        intReturn = gsapi_new_instance(intGSInstanceHandle, callerHandle)

77258840Author Commented:
thats run
well, that's exactly the same as in the sample you posted, just old VB syntax :)
77258840Author Commented:
Not. The diference is
Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal DllInternalPath As String) As Long

Dim DllInternalPath as String = "where you are the gsdll32.dll, in Bin"
Dim Largo As Long = LoadLibrary("DllInternalPath") you dont need register vin a PC or Server the Ghostscript.
Thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now