Mating C# with JavaScript

Visual C++/C/C# related discussions

Moderators: The Coolest, imposter

Post Reply
User avatar
The Coolest
Site Admin
Site Admin
Posts: 3379
Joined: Tue Feb 18, 2003 7:48 pm
Location: Tel Aviv, Israel
Contact:

Mating C# with JavaScript

Post by The Coolest »

Can't get my DLL to load properly in win2003, Vista loads it but no function works.

Here's my C# code:

Code: Select all

using System;
using System.Collections.Generic;
using System.Text;
using GetCoreTempInfoNET;
using System.Runtime.InteropServices;

namespace CoreTempReader
{
    [ComVisible(true)]
    [Guid("083f5ae0-2b0a-11dd-bd0b-0800200c9a66"), ClassInterface(ClassInterfaceType.None)]
    public class Reader: ICoreTempInterface, IDisposable
    {
        private CoreTempInfo CTinfo = new CoreTempInfo();

        public int GetLoad(int index)
        {
            return (int)CTinfo.GetCoreLoad[index];
        }

        public float GetTemp(int index)
        {
            return CTinfo.GetTemp[index];
        }

        public int GetTjMax(int index)
        {
            return (int)CTinfo.GetTjMax[index];
        }

        public void Refresh()
        {
            if (!CTinfo.GetData())
                throw new Exception("An error occured while reading shared memory");
        }

        public int GetCoreCount
        {
            get
            {
                return (int)CTinfo.GetCPUCount;
            }
        }

        #region IDisposable Members

        public void Dispose()
        {            
        }

        #endregion

        #region ICoreTempInterface Members


        public int CoreCount
        {
            get { return (int)CTinfo.GetCPUCount; }
        }

        public int CPUCount
        {
            get { return (int)CTinfo.GetCPUCount; }
        }

        public float VID
        {
            get { return CTinfo.GetVID; }
        }

        public float CPUSpeed
        {
            get { return CTinfo.GetCPUSpeed; }
        }

        public float FSBSpeed
        {
            get { return CTinfo.GetFSBSpeed; }
        }

        public float Multiplier
        {
            get { return CTinfo.GetMultiplier; }
        }

        public string CPUName
        {
            get { return CTinfo.GetCPUName; }
        }

        public bool Fahrenheit
        {
            get { return CTinfo.IsFahrenheit; }
        }

        public bool DeltaToTjMax
        {
            get { return CTinfo.IsDistanceToTjMax; }
        }

        #endregion
    }

    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch), Guid("A52A4CCE-8A96-42b3-9D06-5173E6E6334B")]
    interface ICoreTempInterface
    {
        void Refresh();
        int GetLoad(int Index);
        int GetTjMax(int Index);
        int CoreCount { get; }
        int CPUCount { get; }
        float GetTemp(int Index);
        float VID { get; }
        float CPUSpeed { get; }
        float FSBSpeed { get; }
        float Multiplier { get; }
        string CPUName { get; }
        bool Fahrenheit { get; }
        bool DeltaToTjMax { get; }
    }                            

}
Here's the libhelper.js code

Code: Select all

// ################## CONFIGURATION ###################
var dllCLSID = "{083f5ae0-2b0a-11dd-bd0b-0800200c9a66}";
var Classname = "CoreTempReader.Reader";
var LibPath = "file:///C:/Documents%20and%20Settings/Administrator/Desktop/CoreTemp(1)/CoreTemp/CoreTempReader.dll";
var LibName = "CoreTempReader";
// ####################################################

var oShell = new ActiveXObject("WScript.Shell");

function RegisterLibrary(regRoot) 
{
	var classRoot = regRoot + "\\Software\\Classes\\"+Classname+"\\";
	var clsidRoot = regRoot + "\\Software\\Classes\\CLSID\\" + dllCLSID + "\\";

	try
	{
		oShell.RegWrite(classRoot, Classname, "REG_SZ");
		oShell.RegWrite(classRoot + "CLSID\\", dllCLSID, "REG_SZ");
		oShell.RegWrite(clsidRoot, Classname, "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\", "mscoree.dll", "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\ThreadingModel", "Both", "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\Class", Classname, "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\Assembly", LibName + ", Version=1.0.2588.9125, Culture=neutral, PublicKeyToken=null", "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\RuntimeVersion", "v2.0.50727", "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\CodeBase", LibPath , "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\1.0.2588.9125\\Class", Classname, "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\1.0.2588.9125\\Assembly", LibName + ", Version=1.0.2588.9125, Culture=neutral, PublicKeyToken=null", "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\1.0.2588.9125\\RuntimeVersion", "v2.0.50727", "REG_SZ");
		oShell.RegWrite(clsidRoot + "InprocServer32\\1.0.2588.9125\\CodeBase", LibPath , "REG_SZ");
		oShell.RegWrite(clsidRoot + "ProgId\\", Classname , "REG_SZ");
		oShell.RegWrite(clsidRoot + "ProgId\\Implemented Categories\\{df21d370-2b10-11dd-bd0b-0800200c9a66}\\", "", "REG_SZ");
	}
	catch(err) 
	{
	    return null;
	}
	return new ActiveXObject(Classname);
}

function GetLibrary()
{
    var Lib;
    Lib = RegisterLibrary("HKCU");
    if (Lib == null)
  	  Lib = RegisterLibrary("HKLM");
    return Lib;
}
And just for the hell of it the gadget.js code

Code: Select all

var CoreTemp = GetLibrary();
var CoreTempActive;
 
function onLoad()
{
debugger;
    onTimer();
    setInterval("onTimer()",1000);
}

function onTimer()
{
    refreshdisplay();
}

function refreshdisplay()
{
    var t1 = 0;
    var t2 = 0;
    var t3 = 0;
    var t4 = 0;
    
    var l1 = 0;
    var l2 = 0;
    var l3 = 0;
    var l4 = 0;
    
    var cn = "coretemp not running!";
    var cc = "";
    var cf = false;
    var ci = "";
    
    if (CoreTemp == null)
    {
        cpuName.innerHTML = "load library error!";
        return;
    }
    try
    { 
        CoreTemp.Refresh();
        alert("Refreshed");
    } catch (err) {cpuName.innerHTML = err.message;} 
    var coreCount;
    coreCount = CoreTemp.CoreCount;
    alert(coreCount);
    if (coreCount > 0)
    {
        try
        {        
            t1 = parseInt(CoreTemp.GetTemp(0));
            t2 = parseInt(CoreTemp.GetTemp(1));
            t3 = parseInt(CoreTemp.GetTemp(2));
            t4 = parseInt(CoreTemp.GetTemp(3));

            l1 = CoreTemp.GetLoad(0);
            l2 = CoreTemp.GetLoad(1);
            l3 = CoreTemp.GetLoad(2);
            l4 = CoreTemp.GetLoad(3);
            
            cn = CoreTemp.CPUName;
            cc = "Clock: " + CoreTemp.CPUSpeed.toFixed(0) + "Mhz("+ CoreTemp.FSBSpeed.toFixed(2)+"x"+CoreTemp.Multiplier.toFixed(1)+")";
            cf = CoreTemp.Fahrenheit;
            ci =  "VID: " + CoreTemp.VID.toFixed(4) + "V - TjMax: " +  CoreTemp.GetTjMax(0) + (cf ? "°F" : "°C");
            
            if (!CoreTempActive)
            {
                CoreTempActive = true;
                buildGUI();
            }
        }
        catch (err) {cpuName.innerHTML = err.message;}

        
        tmpCore1.innerHTML = (t1 == 0) ? "Core #1" : "[ " + t1 + (cf ? "°F" : "°C") + " ] "; 
        usgCore1.innerHTML = l1 + "%";
        bar1.style.width = parseInt( 0.5 * l1 );
        
        if (coreCount > 1)
        {
            tmpCore2.innerHTML = (t2 == 0) ? "Core #2" : "[ " + t2 + (cf ? "°F" : "°C") + " ] ";
            usgCore2.innerHTML = l2 + "%";
            bar2.style.width = parseInt( 0.5 * l2 );
        }

        if (coreCount > 2)
        {
            tmpCore3.innerHTML = (t3 == 0) ? "Core #3" : "[ " + t3 + (cf ? "°F" : "°C") + " ] ";
            usgCore3.innerHTML = l3 + "%";
            bar3.style.width = parseInt( 0.5 * l3 );
        }

        if (coreCount > 3)
        {
            tmpCore4.innerHTML = (t4 == 0) ? "Core #4" : "[ " + t4 + (cf ? "°F" : "°C") + " ] ";
            usgCore4.innerHTML = l4 + "%";
            bar4.style.width = parseInt( 0.5 * l4 );
        }
    }
    else
    {
        if (CoreTempActive)
        {
            CoreTempActive = false;
            buildGUI();
        }
    }
        
    
    cpuName.innerHTML = cn;
    cpuClock.innerHTML = cc;
    cpuInfo.innerHTML =  ci;
}    


function buildGUI()
{
    resetGUI();
    try 
    {
        var coreCount = CoreTemp.CoreCount;
        coreCount = 0;
        
        alert("HI " + coreCount);
    }
    catch(err)
    {
        cpuName.innerHTML = err.message;
        coreCount = 0;
        alert("HI2 " + coreCount);
    }
    try 
    {
        if (coreCount < 4)
        {
            back4.style.visibility = "hidden";
            bar4.style.visibility = "hidden";
            tmpCore4.style.visibility = "hidden";
            usgCore4.style.visibility = "hidden";
            background.style.height = 92;
            document.body.style.height = 92;
        } 
        if (coreCount < 3)
        {
            back3.style.visibility = "hidden";
            bar3.style.visibility = "hidden";
            tmpCore3.style.visibility = "hidden";
            usgCore3.style.visibility = "hidden";
            background.style.height = 82;
            document.body.style.height = 82;
        }
        if (coreCount < 2)
        {
            back2.style.visibility = "hidden";
            bar2.style.visibility = "hidden";
            tmpCore2.style.visibility = "hidden";
            usgCore2.style.visibility = "hidden";
            background.style.height = 72;
            document.body.style.height = 72;
        }
        if (coreCount < 1)
        {
            back1.style.visibility = "hidden";
            bar1.style.visibility = "hidden";
            tmpCore1.style.visibility = "hidden";
            usgCore1.style.visibility = "hidden";
            background.style.height = 62;
            document.body.style.height = 62;
        }
    }
    catch(err)
    {
        cpuName.innerHTML = err.message;
    }            
}

function resetGUI()
{
    background.style.height = 102;
    document.body.style.height = 102;
    back4.style.visibility = "visible";
    bar4.style.visibility = "visible";
    tmpCore4.style.visibility = "visible";
    usgCore4.style.visibility = "visible";
    back3.style.visibility = "visible";
    bar3.style.visibility = "visible";
    tmpCore3.style.visibility = "visible";
    usgCore3.style.visibility = "visible";
    back2.style.visibility = "visible";
    bar2.style.visibility = "visible";
    tmpCore2.style.visibility = "visible";
    usgCore2.style.visibility = "visible";
    back1.style.visibility = "visible";
    bar1.style.visibility = "visible";
    tmpCore1.style.visibility = "visible";
    usgCore1.style.visibility = "visible";
}
Main rig:
AMD Ryzen 9 5950X (True Spirit 140 Direct) / Mobo: Asrock Fatal1ty X470 / EVO 970 500GB + WD Blue 250GB + HDD / GPU: Dell RX 570 4GB / Mem: 2x16GB DDR4-3200 G.Skill 32GTZKW TridentZ - 32GB total / PSU: Seasonic Prime Ultra Gold 650W
NAS:
Core i7 2600K 3.4GHz @ 4.3GHz (Scythe Mugen2) / Mobo: Biostar TP67XE / 2x Inland Pro 120GB + HDDs / GPU: ATi Mach64 VT2 / Mem: 4x4GB DDR3-1600 G.Skill 8GBXL RipJawsX - 16GB total / PSU: Seasonic S12II 620W.
Secondary rigs:
Core i3 7130U / MiniPC / SanDisk SDSSDP-128G / GPU: Intel HD 620 / Mem: 1x8GB DDR3L-1600
Xeon X3430 2.40GHz @ 3.06GHz or Core i3 540 3.06GHz @ 4.0GHz (Freezer 7 Pro) / Mobo: MSI H55M-ED55 / PNY CS1111 240GB / GPU: ATI FirePro V3800 / Mem: 4x2GB DDR3-1600 G.Skill 4GBRL RipJaws - 8GB total / PSU: Seasonic S12II 620W
AMD Phenom II X4 B93 / Mobo: ASUS M2A-VM / GPU: ATI Radeon Xpress X1250 / Crucial M4 120GB / Mem: 2x2GB DDR2-800 - 4GB total / PSU: Antec 380W.

Core Temp - Accurate temperature monitor for Intel's Core/Core 2 and AMD64 processors

User avatar
The Coolest
Site Admin
Site Admin
Posts: 3379
Joined: Tue Feb 18, 2003 7:48 pm
Location: Tel Aviv, Israel
Contact:

Post by The Coolest »

Of course.... the damn interface is supposed to be public....
Main rig:
AMD Ryzen 9 5950X (True Spirit 140 Direct) / Mobo: Asrock Fatal1ty X470 / EVO 970 500GB + WD Blue 250GB + HDD / GPU: Dell RX 570 4GB / Mem: 2x16GB DDR4-3200 G.Skill 32GTZKW TridentZ - 32GB total / PSU: Seasonic Prime Ultra Gold 650W
NAS:
Core i7 2600K 3.4GHz @ 4.3GHz (Scythe Mugen2) / Mobo: Biostar TP67XE / 2x Inland Pro 120GB + HDDs / GPU: ATi Mach64 VT2 / Mem: 4x4GB DDR3-1600 G.Skill 8GBXL RipJawsX - 16GB total / PSU: Seasonic S12II 620W.
Secondary rigs:
Core i3 7130U / MiniPC / SanDisk SDSSDP-128G / GPU: Intel HD 620 / Mem: 1x8GB DDR3L-1600
Xeon X3430 2.40GHz @ 3.06GHz or Core i3 540 3.06GHz @ 4.0GHz (Freezer 7 Pro) / Mobo: MSI H55M-ED55 / PNY CS1111 240GB / GPU: ATI FirePro V3800 / Mem: 4x2GB DDR3-1600 G.Skill 4GBRL RipJaws - 8GB total / PSU: Seasonic S12II 620W
AMD Phenom II X4 B93 / Mobo: ASUS M2A-VM / GPU: ATI Radeon Xpress X1250 / Crucial M4 120GB / Mem: 2x2GB DDR2-800 - 4GB total / PSU: Antec 380W.

Core Temp - Accurate temperature monitor for Intel's Core/Core 2 and AMD64 processors

Post Reply

Return to “Visual C++/C/C#”